-
Notifications
You must be signed in to change notification settings - Fork 555
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
more type-hinting for SPARQL plugin #2265
Conversation
Thanks for the PR @jclerman, looks good from a very brief glance - I'm planning to release today, but will see if I can include this, I may make some changes directly to your branch though if needed, but i will try to keep it minimal. |
Sure thing @aucampia. Total coincidence that I submitted this today; hadn't realized you were about to make a release - but it'd be great if this could be included! Minor changes are fine, certainly. Not sure if the flake8 violation should be fixed or allowed - I named the test after a function, and because the function had capital letters in its name, the test does too. I don't mind breaking that symmetry if we'd prefer not to add more flake8 violations. |
For those I will just add |
…mprove type-hinting
0d19ad4
to
fcec02e
Compare
try: | ||
return chr(int(m.group(1), 16)) | ||
except: # noqa: E722 | ||
raise Exception("Invalid unicode code point: " + m) | ||
except (ValueError, OverflowError) as e: |
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'm not sure if OverflowError
could be raised from here, not that it is that much of a problem if it can't but would like to know just for interest’s sake.
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.
In my local testing I found that OverflowError
could be raised for large 8-digit hexadecimal codepoint numbers - apparently because they can be larger than a 32-bit int. I'm not sure why the max isn't 64-bit, but that might be a limitation caused by the use of int()
.
Valid codepoints can't be larger than \U10000000
, so it's kind of a moot point, except that due to the way the regex is written, the function will try to handle \U99999999
and will trigger OverflowError
.
This is more accurate and eliminates type errors.
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 made a very small change, adding BinaryIO
in addition to TextIO
, as that should also work. Everything looks great otherwise, thanks again for this.
I plan to merge with only one review unless there is more feedback soon, as I want to finish the release today and there are more changes I want to get in for SPARQL typing, as the current typing in |
Summary of changes
Here, adding type-hints to some of the SPARQL parser plugin code.
Includes a couple of small consequent changes:
prettify_parsetree()
, separating the public-facing callable from the internal code that does not need to be public-facing. That allows the public-facing callable to have more informative and restrictive type-hints for its arguments.expandUnicodeEscapes()
- initially for my own understanding, but seems useful to leave it in place since I didn't see test-coverage for that function.There should be no backwards-incompatible changes in this PR - at least, not intentionally.
Checklist
the same change.
./examples
for new features.CHANGELOG.md
).so maintainers can fix minor issues and keep your PR up to date.