-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Use PEP 604 syntax wherever possible #7493
Conversation
@erictraut, looks like there's some pyright bugs when it comes to using |
This comment has been minimized.
This comment has been minimized.
Looking into it now. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
Thank you!! |
This comment has been minimized.
This comment has been minimized.
3 similar comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@AlexWaygood, you hit two bugs in pyright's handling of PEP 604. Both of them involved the heuristics that pyright uses to detect the difference between a variable assignment and an implied type alias declaration (i.e. one that doesn't involve an explicit The first bug involves the use of The second bug involves the use of a TypeVar within an implicit type alias that uses PEP 604 syntax. The workaround for this is to add an explicit Both of these will be fixed in the next release of pyright (1.1.230) which I plan to publish later today. |
Unfortunately we can't use TypeAlias in typeshed yet because pytype doesn't support it (#4913). Thanks as always for the quick response @erictraut! |
Let me second @JelleZijlstra — your response time is always incredible @erictraut; thank you for all the time and energy you put into open source software! |
This comment has been minimized.
This comment has been minimized.
@nipunn1313, this PR makes some stylistic changes to a few of the protobuf stubs. I know some of those are autogenerated -- is modifying those files going to cause problems? (I'm happy to revert the changes to those files, if so!) |
Yep! The autogenerated files are autogenerated, so the stylistic updates aren't going to stay permanently. I think it'll be better to revert them out of this diff. However, I can make the stylistic changes to mypy-protobuf (file me an issue over there), such that we're able to get the benefits over here. I can send a PR to typeshed once we release a mypy-protobuf that includes the PEP604 syntax. |
Thanks! I've reverted all proposed changes in the Tbh I wouldn't worry too much about updating mypy-protobuf just yet, since there's still a few situations where we can't use the new-style syntax in typeshed due to mypy bugs. (The bugs specifically involve unions that include |
This comment has been minimized.
This comment has been minimized.
No CI for you. |
...Could you possibly try closing and reopening this PR? Is it something to do with me?? |
No CI for me either. :( But GitHub seemed laggy just now. |
Okay Github Actions is obviously having a bad day. |
Don't know where the mypy_primer comment has got to, but the CI is finally green, and the uploaded mypy_primer diffs are all empty 🥳 |
This comment has been minimized.
This comment has been minimized.
2 similar comments
This comment has been minimized.
This comment has been minimized.
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
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.
Not going to check this in depth, but LGTM.
Sorry about breaking pyright-action; you should be able to revert the change to the action's version now, I've published a fix. |
I noticed that we seem to be holding up usage of TypeAlias in typeshed: python/typeshed#7493 (comment). TypeAlias is relatively simple, so I went ahead and added support for it in both .py and .pyi files. Resolves #787. PiperOrigin-RevId: 435095246
Not currently possible for some unions involving
tuple
(see python/mypy#11098), and one or two unions involvingtype[T]
and/orCallable
.Script: