fixed template and parser function "=" semantic - #150
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #150 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 16 16
Lines 2270 2326 +56
=========================================
+ Hits 2270 2326 +56 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
I can't see Codecov report, got error 400. |
efc9d63 to
dd29fb1
Compare
|
Ok I amended my commit but I still don't understand what's the problem with Codecov, it gets angry because of |
|
Ok I amended one more time, now I understand what was wrong. The |
|
Thanks! I like the overall direction here, especially moving One thing I'm not quite comfortable with is making
To make the implementation general enough to handle all cases, I'd suggest keeping For example, the API could look roughly like: def get_arg(self, name, *, ignore_equals=True):
...so that the caller can explicitly choose the semantics when needed: pf = ParserFunction('{{#ifeq:a|b|c|d}}')
pf.set_arg('1', 'b', ignore_equals=True)
pf = ParserFunction('{{#switch:var|case1= 1 | case2 = 2 }}')
pf.set_arg('case2', 'b', ignore_equals=False)Conceptually, Some other parser functions where = is treated as a separator in them: |
|
@5j9 Would be viable to fetch a list of parser functions names where the "=" must not be ignored, and use this same list to define a default behavior of |
Parser function names can be translated, so we'd have to keep track of all those translations across languages and over time. That would make the implementation and maintenance considerably more complicated, and I don't think it's worth it. |
|
Also, Here the second argument is always positional, even though its value contains |
@5j9 Sorry if I don't let you sleep, but I have an arsenal of PRs to cast one by one. Let's focus on the next problem: parser functions inherit template "=" semantic. My proposal is:
_parser_function.py. WhySubWikiTextArgsis on this file while it has to be used on bothTemplateandParserFunctionclass? Why not puttingParserFunctionandTemplateat the same hierarchy, while both classes inheritSubWikiTextArgsfrom somewhere else? Then, movedSubWikiTextArgsto_argument.py. Now, both_template.oyand_parser_function.pyrequire this parent class from the same file, which is a more natural organization.ParserFunctionandTemplateclasses. Now both will have a variable called_ignore_equals, which is a boolean that defines "=" behiavor. On parser functions "=" character is ignored.ParserFunction, added methodsset_arg,get_arg,del_argandhas_arg. These methods only work with numbers as argument names, since pf's can only have positional arguments (of course, you can consider#switchas an exception but omit that case for today :))set_arg. What happens if yout.set_arg('2', 'a', positional=True) for t = {{t}}? Well, I think the criteria was (and is, and I enforced):None, then append a positional (unnamed) argument.Noneand is NEW then will be positional iffpositional==TrueAND is integer and is right after last index of positional arguments (henceget_last_idx_positional_args).Noneand is ALREADY EXISTENT, then positional defines whether this argument has to be converted to positional (i.e., remove the name of the argument in the template). Converting from positional to keyword raises an exception.ParserFunction, ifset_argis called with a not integer name, the function currently does nothing, but we can throw an exception if you prefer.