KEMBAR78
Support `TypeAliasType` by hamdanal · Pull Request #16926 · python/mypy · GitHub
Skip to content

Conversation

hamdanal
Copy link
Collaborator

@hamdanal hamdanal commented Feb 17, 2024

Builds on top of and supersedes #16644

@github-actions

This comment has been minimized.

Copy link
Member

@JelleZijlstra JelleZijlstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thank you!

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]"
Copy link
Member

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?

Copy link
Collaborator Author

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.

Copy link
Member

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.

@hamdanal hamdanal marked this pull request as draft February 20, 2024 20:48
@github-actions

This comment has been minimized.

@hamdanal hamdanal marked this pull request as ready for review February 20, 2024 21:29
@github-actions

This comment has been minimized.

Copy link
Member

@JelleZijlstra JelleZijlstra left a 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
Comment on lines 1455 to 1464
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
Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

@hamdanal hamdanal Feb 22, 2024

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

@github-actions

This comment has been minimized.

@JelleZijlstra
Copy link
Member

Tests are failing, I think because the *Ts syntax is 3.12 only. Maybe split that part of the test into its own case and make it run --python-version 3.12.

@hamdanal
Copy link
Collaborator Author

Tests are failing, I think because the *Ts syntax is 3.12 only. Maybe split that part of the test into its own case and make it run --python-version 3.12.

This is already the case. Maybe I’ll need to move the test to a Python 3.12+ test file?

@github-actions

This comment has been minimized.

@hamdanal hamdanal marked this pull request as draft February 22, 2024 07:40
@hamdanal hamdanal marked this pull request as ready for review February 22, 2024 20:31
@github-actions

This comment has been minimized.

@JelleZijlstra JelleZijlstra self-requested a review March 11, 2024 04:40
@JelleZijlstra JelleZijlstra self-assigned this Mar 11, 2024
@github-actions
Copy link
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@JelleZijlstra JelleZijlstra merged commit ea49e1f into python:master Mar 11, 2024
@hamdanal hamdanal deleted the issue-16614 branch March 14, 2024 18:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants