-
-
Notifications
You must be signed in to change notification settings - Fork 2.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
Support TypeAliasType
#16926
Support TypeAliasType
#16926
Conversation
This comment has been minimized.
This comment has been minimized.
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.
Nice, thank you!
@@ -3124,8 +3124,8 @@ def dec(f: Callable[P, T]) -> Callable[P, List[T]]: ... | |||
def id(x: U) -> U: ... | |||
def either(x: U, y: U) -> U: ... | |||
def pair(x: U, y: V) -> Tuple[U, V]: ... | |||
reveal_type(dec(id)) # N: Revealed type is "def [T] (x: T`2) -> builtins.list[T`2]" | |||
reveal_type(dec(either)) # N: Revealed type is "def [T] (x: T`4, y: T`4) -> builtins.list[T`4]" | |||
reveal_type(dec(id)) # N: Revealed type is "def [T] (x: T`3) -> builtins.list[T`3]" |
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.
Do you know why this changed?
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 have no idea to be honest. They changed in the original PR by sobolevn and I didn't know why. I'll do some more digging.
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.
Thanks. Not too important if it's hard to figure out, I assume these numbers can change based on all kinds of factors.
1df0dd2
to
7ffa87f
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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.
Almost there, added a suggestion for improving wording
mypy/typeanal.py
Outdated
if self.defining_alias and self.has_type_params: | ||
tvar_likes = self.find_type_var_likes(arg) | ||
for name, tvar_expr in tvar_likes: | ||
if (name, tvar_expr) not in self.allowed_alias_tvars: | ||
self.fail( | ||
f'Type variable "{name}" is not included in type_params', | ||
arglist, | ||
code=codes.VALID_TYPE, | ||
) | ||
return None |
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.
Added this to handle Callable[[Unpack[Ts]], Ret]
when Ts
is not declared in the type parameters. It was causing a crash.
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 think I'll revert this part, I don't think it is the correct solution 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.
OK so looks like this already crashes on master with old aliases https://mypy-play.net/?mypy=master&python=3.12&gist=744b559e656f6f35cd5762bddf979038. I'll open an issue to track it.
Edit: #16937
This comment has been minimized.
This comment has been minimized.
Tests are failing, I think because the |
This is already the case. Maybe I’ll need to move the test to a Python 3.12+ test file? |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
Builds on top of and supersedes #16644