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 2296 +26
=========================================
+ Hits 2270 2296 +26 ☔ 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 I had to rework the |
|
There is a problem with |
|
I don't think the existing My original thought was that this could perhaps be implemented without changing If some change to In other words, I think we should be able to preserve the existing I'm not suggesting that Regarding More generally, I think it's fine if some tests or other parts of One other small point: moving That said, I don't want to discourage the refactoring — I think the move itself makes sense. I'm mainly thinking about keeping the current PR focused and making the substantive argument-handling changes easier to review. |
|
@5j9 I don't understand why not merge both But both things come togheter, so if the problem is the "scope" of the PR, let there be cancelled so I open a "broader" PR. Regarding |
|
Regarding merging the If you mean removing If you mean keeping Regarding the scope, I wouldn't worry too much about whether the PR is “too broad” in itself. My concern is mainly that a larger PR naturally takes longer to review, especially when it involves both a behavioral change and a substantial refactoring. So if you make it broader, that's fine; just keep in mind that it may take me longer to get through it. I don't think there's a need to cancel the current PR just because of the scope. I'd rather first settle on what the desired API and structure should be, and then we can decide whether the current PR should be revised or made broader. Regarding I think its current behavior is correct for So I think that part can be handled without changing the existing |
|
@5j9 What I mean is to add all the shared logic into parent class Regarding
OK? |
|
Yes, that sounds mostly OK to me. For I'm also fine with keeping Regarding What I'd like to understand here is primarily what existing behavior is changing and why. The opening message describes what the new behavior should be, but it doesn't really explain what the PR is changing compared with the current behavior, or which existing cases were ambiguous or incorrect. Since the behavior around the first parameter, positional arguments, and |
@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.