-
Notifications
You must be signed in to change notification settings - Fork 139
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
refactor(ext.commands): completely rewrite Range
and String
, require type argument
#991
Conversation
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.
This ends up being a breaking change, yet isn't documented as such.
edit: nevermind, tested incorrectly.
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.
Haven't tested, but implementation-wise, this looks good to me ^^
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.
This is backwards compatible, but I'm not sure about the changes to String, why does String need the type argument?
Afaik that's just to make it work with edit: |
exactly this - |
Summary
(I recommend using the split diff for looking at the changes in this PR, the unified diff is fairly unreadable as-is.)
As of pyright 1.1.299,
Range[1, 2]
is no longer accepted; that old syntax was sort of abusing__class_getitem__
before, so this is an issue on our end.This PR completely reworks
Range
andString
, adding a ton of validation+tests and making them work with recent versions of pyright and mypy without misusing the type system c:The new implementation is based on the general idea of aliasing these types to
typing.Annotated
at type-checking time.The old
Range[1, 2]
syntax is deprecated, but still works (at runtime), for now; the new/proper way to use them isRange[int, 1, 2]
,Range[float, 1, 2]
, andString[str, 1, 2]
.In the same vein, the mypy plugin that was added later and made these work is now a stub,
raising a deprecation warning.Unresolved Issues
2**53
as expected, float bounds quietly lose precision past(-)2**53
on the API side. Should we emit warnings/errors when going above/below that?Checklist
pdm lint
pdm pyright