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

Support TypeAliasType #16926

Merged
merged 18 commits into from
Mar 11, 2024
Merged

Support TypeAliasType #16926

merged 18 commits into from
Mar 11, 2024

Conversation

hamdanal
Copy link
Collaborator

@hamdanal hamdanal commented Feb 17, 2024

Builds on top of and supersedes #16644

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!

mypy/semanal.py Outdated Show resolved Hide resolved
@@ -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]"
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.

test-data/unit/check-type-aliases.test Outdated Show resolved Hide resolved
test-data/unit/check-type-aliases.test Show resolved Hide resolved
test-data/unit/check-type-aliases.test Outdated Show resolved Hide resolved
test-data/unit/check-type-aliases.test Show resolved Hide resolved
@hamdanal hamdanal marked this pull request as draft February 20, 2024 20:48

This comment has been minimized.

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

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/semanal.py Outdated Show resolved Hide resolved
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

test-data/unit/check-type-aliases.test Outdated Show resolved Hide resolved

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?

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

This comment has been minimized.

@JelleZijlstra JelleZijlstra self-requested a review March 11, 2024 04:40
mypy/semanal.py Outdated Show resolved Hide resolved
@JelleZijlstra JelleZijlstra self-assigned this Mar 11, 2024
mypy/semanal.py Outdated Show resolved Hide resolved
mypy/semanal.py Outdated Show resolved Hide resolved
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
18 checks passed
@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