-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix duration parsing in lists #255
Fix duration parsing in lists #255
Conversation
84d12b2
to
70d9586
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this.
It's not clear what the first commit is fixing (though I agree it's an improvement). Can you provide a test that was previously failing?
The second commit includes a significant refactoring of the code in addition to the bug fix (which is small), making it hard to spot. (I think it's only adding "isinstance(token, str) and"?)
Can you split that into two commits so the fix is more obvious?
The magic here is the `Or()` operator that tries to match the longest pattern.
The relativedelta objects were rejected because we cannot compare them to strings. Both `==` and `!=` results to `False`. Instead we have to first test the type and then do the comparison.
70d9586
to
16a4386
Compare
I went through the code once again to see if I can split it into multiple commits with tests. The answer is no. A test that is added addresses both bugs. The first bug is that the regex that we used to match durations was matching the end of the line because there was
but this was matched OK (hocon file):
The problem here was clearly the regex. Once I fixed this I noticed that the test I wrote doesn't work. The parsed config didn't match the expected value and for some reason, the duration value was omitted from the list. If I put this into the config:
the parsed result was missing a value:
This is the second bug I addressed. As you pointed out the trick was to include the type check
Once I fixed this the test was passing. I opened a single PR as I believe the bugs are related to each other. I don't think there is a way to write a separate test for each commit. I reviewed the commits and improved some comments plus I dropped the unneeded import that I moved from a function scope to the module scope (this was an unrelated change). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see the issue and I agree about the tests. Thanks for the explanation.
I won't harp on this anymore but I still think the refactoring should be a separate commit from the bug fix.
Any update on this, please? |
I created my own branch to explain what I meant about splitting up the refactoring from the bugfix. Commit 195b0e9 does the refactoring, then 588ed9a applies the bugfix. By splitting them up this way, it clarifies exactly how the fix works. Sadly, it seems that @chimpler has abandoned this repo. |
Feel free to close this PR and merge your changes if you have permission to do so. |
Thank you @olii! |
There are two changes:
pyparsing
objects. Most important isOr()
operator that matches the longest match.ListParser.postParse()
that ignored some object types.This fixes: #252