-
Notifications
You must be signed in to change notification settings - Fork 578
Fix parser bug and add test #2943
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
Conversation
Thanks for fixing the unrelated error. I've pushed the fix into |
rdflib/plugins/sparql/parser.py
Outdated
if i + 1 < l_ and terms[i + 1] not in ".,;": | ||
if i + 1 < l_ and not any(terms[i + 1] == token for token in ".,;"): |
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've tried to interpret this code change several times, and it seems to be the logic of the pre-fix state and post-fix state is functionally identical.
- If this term is not any of the characters in this string, vs
- None of the characters in this string are my term.
Clearly it has fixed the issue, the tests are passing, but I'm not clear on how the change works.
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.
The issue is that the terms are not always strings. The __eq__
method on CompValue
successfully returns False
in this case, but the __contains__
method on str
apparently raises a type error, although I can’t find any documentation of this behaviour. Compare with the similar test on line 72.
Edit: The test we're running afoul of is here.
Edit 2: This is likely because __contains__
on str
is defined in terms of substrings, rather then the usual container membership. The functionality we want here is, however, container membership. A simpler fix might have been to make the string into a simpler container:
if i + 1 < l_ and terms[i + 1] not in list(".,;"):
or simply avoid representing lists as strings in the first place:
if i + 1 < l_ and terms[i + 1] not in [".", ",", ";"]:
Edit 3: I changed to the last version with a brief comment. (Sadly it is four lines longer after black formatting.)
Summary of changes
The where clause:
should be treated identically to:
Instead it fails with:
I believe the first pattern is valid based on the fourth example given in §4.1.4 of the SPARQL 1.2 spec.
Checklist
the same change.
so maintainers can fix minor issues and keep your PR up to date.