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

Consider supporting from typing import * #2282

Closed
dimaqq opened this issue Sep 9, 2021 · 3 comments
Closed

Consider supporting from typing import * #2282

dimaqq opened this issue Sep 9, 2021 · 3 comments
Labels
as designed Not a bug, working as intended enhancement request New feature or request

Comments

@dimaqq
Copy link

dimaqq commented Sep 9, 2021

I understand the ban on star imports in general,
however, it seems that specifically from typing import * became kindof idiomatic.
I wonder if this specific stanza could be supported.

P.S. I personally don't do this, but work on others' code that does.

@dimaqq dimaqq added the enhancement request New feature or request label Sep 9, 2021
@erictraut
Copy link
Collaborator

I would highly recommend against using wildcard imports from libraries. It's an extremely dangerous practice that leads to code fragility. New symbols are introduced to the typing module every release, and you risk local namespace collisions when upgrading.

I'm not aware of wildcard imports from typing becoming idiomatic. I've seen it used as a shorthand in a few sample snippets and bug reports, but I've never seen it used in actual code.

If you don't want to see the warning, you can disable the reportWildcardImportFromLibrary diagnostic check in your project.

@erictraut erictraut added the as designed Not a bug, working as intended label Sep 9, 2021
@dimaqq
Copy link
Author

dimaqq commented Sep 9, 2021

🤔 grepping through my site-packages, it seem that only one developer uses that idiom... I guess I can try to fix a few libraries 🤔

@dimaqq
Copy link
Author

dimaqq commented Sep 9, 2021

New symbols are introduced to the typing module every release

This actually got me thinking, surely Python minor releases are backwards compatible and reasonably forwards-compatible...

I've tested this on 3.7, 3.8, 3.9 and 3.10 with:

>>> before = set(locals())
>>> from typing import *
>>> after = set(locals())
>>> after - before

It turns out that backwards compatibility is perfect:

In [10]: p7 < p8 < p9 < p10
Out[10]: True

Here's what got added:

In [14]: print(" ".join(p10 - p9))
is_typeddict Pattern ParamSpecArgs BinaryIO Match ParamSpec TypeAlias Concatenate TextIO ParamSpecKwargs TypeGuard IO

In [15]: print(" ".join(p9 - p8))
Annotated

In [16]: print(" ".join(p8 - p7))
Literal Protocol get_args runtime_checkable Final TypedDict get_origin SupportsIndex final

Posting it here in case someone wonders about that, or is looking to stop using from typing import *

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
as designed Not a bug, working as intended enhancement request New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants