-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Fix Unpack imported from typing #14378
Conversation
This comment has been minimized.
This comment has been minimized.
mypy/semanal.py
Outdated
@@ -1881,7 +1881,7 @@ def analyze_unbound_tvar(self, t: Type) -> tuple[str, TypeVarLikeExpr] | None: | |||
# It's bound by our type variable scope | |||
return None | |||
return unbound.name, sym.node | |||
if sym and sym.fullname == "typing_extensions.Unpack": | |||
if sym and sym.fullname in {"typing.Unpack", "typing_extensions.Unpack"}: |
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.
if sym and sym.fullname in {"typing.Unpack", "typing_extensions.Unpack"}: | |
if sym and sym.fullname in ("typing.Unpack", "typing_extensions.Unpack"): |
Nit, but this is what most other similar checks look like and I suspect mypyc handles it better. It's likely also faster in non-compiled Python to use a tuple here.
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 sure about mypyc, but for non-compiled Python it's actually a toss-up for two items. However, starting with three, sets are usually better.
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.
I ran some local benchmarks and set is faster even for two-element tuples when the element is the second one. Still, better to be consistent with the other mypy code.
Co-authored-by: Jelle Zijlstra <[email protected]>
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
Add missing check for
typing.Unpack
to fix running with--python 3.11
.