-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Add constants for Concatenate and Unpack type names #18553
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -130,6 +130,12 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Supported Annotated type names. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ANNOTATED_TYPE_NAMES: Final = ("typing.Annotated", "typing_extensions.Annotated") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Supported Concatenate type names. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CONCATENATE_TYPE_NAMES: Final = ("typing.Concatenate", "typing_extensions.Concatenate") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Supported Unpack type names. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| UNPACK_TYPE_NAMES: Final = ("typing.Unpack", "typing_extensions.Unpack") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would probably be slightly faster with current mypyc to annotated these as
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are quite a few of these already with just Just for pure Python, using Lines 112 to 134 in f49a1cb
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From my initial testing it looks like your hunch was correct. While is faster to construct the The bigger performance gain would be to optimize for contains. They are nearly exclusively used with Mypyc doesn't seem to optimize frozenset yet, does it? AFAICT it still uses Lines 610 to 619 in d4e7a81
--
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mypyc doesn't optimize frozenset much. And in small collections linear search may be faster than a set lookup. The best long-term solution is for mypyc to optimize
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did some performance testing today. AFAICT the difference is below the noice. Probably indeed not worth it at this point. The main advantage this change provided is that devs don't accidentally miss on of the type names if they reuse it. IIRC this happened for |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Supported @deprecated type names | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| DEPRECATED_TYPE_NAMES: Final = ("warnings.deprecated", "typing_extensions.deprecated") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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.
mypy/mypy/types.py
Lines 87 to 94 in 82f4e88