Skip to content
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

Some typing_extensions rewrites are perhaps overly aggressive #842

Closed
AlexWaygood opened this issue Jun 16, 2023 · 1 comment
Closed

Some typing_extensions rewrites are perhaps overly aggressive #842

AlexWaygood opened this issue Jun 16, 2023 · 1 comment

Comments

@AlexWaygood
Copy link
Contributor

AlexWaygood commented Jun 16, 2023

Hi, thanks so much for pyupgrade -- I think it's a fantastic tool.

When run with e.g. the --py39-plus flag, pyupgrade will currently make the following changes, which are perhaps overly aggressive:

-from typing_extensions import Protocol
-from typing_extensions import SupportsIndex
-from typing_extensions import NewType
+from typing import Protocol
+from typing import SupportsIndex
+from typing import NewType

In the latest version of typing_extensions, several performance improvements (and several bugfixes) from Python 3.12 have been backported to typing_extensions.Protocol. The upshot of this is that isinstance() checks against runtime-checkable protocols may be 20x faster or more if you're using typing_extensions.Protocol. The same rationale applies for why a user might want to use typing_extensions.SupportsIndex rather than typing.SupportsIndex.

The latest version of typing_extensions also backports the implementation of typing.NewType from Python 3.10 to older Python versions. In Python 3.10, NewType is implemented as a class, which makes newtypes pickleable; on earlier versions of Python, newtypes were not pickleable. (This backport was done in response to a request from a user who was struggling to use multiprocessing with typing.NewType on older Python versions due to the fact that newtypes could not be pickled.)

@asottile
Copy link
Owner

if you want to update the symbols they're generated in https://github.com/asottile/reorder-python-imports -- there's already several carveouts for typing-extensions there as well so it's easy to add more

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants