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

Disallow bare ParamSpec in type aliases #18174

Merged

Conversation

brianschubert
Copy link
Collaborator

Emit errors for both of the following aliases:

P = ParamSpec("P")
Bad1: TypeAlias = P
Bad2: TypeAlias = Concatenate[int, P]

This is done by swapping a top-level call to type.accept(analyzer) with analyzer.anal_type(type), the latter of which simply calls the former and then performs some checks.

@brianschubert
Copy link
Collaborator Author

Conformance results diff for this PR (generics_paramspec_basic now passes):

diff --git a/conformance/results/mypy/generics_paramspec_basic.toml b/conformance/results/mypy/generics_paramspec_basic.toml
index 53fd4f5..a22eb7b 100644
--- a/conformance/results/mypy/generics_paramspec_basic.toml
+++ b/conformance/results/mypy/generics_paramspec_basic.toml
@@ -4,6 +4,8 @@ Does not reject ParamSpec when used "bare" in type alias definition.
 """
 output = """
 generics_paramspec_basic.py:10: error: String argument 1 "NotIt" to ParamSpec(...) does not match variable name "WrongName"  [misc]
+generics_paramspec_basic.py:15: error: Invalid location for ParamSpec "P"  [valid-type]
+generics_paramspec_basic.py:15: note: You can use ParamSpec as the first argument to Callable, e.g., "Callable[P, int]"
 generics_paramspec_basic.py:23: error: Invalid location for ParamSpec "P"  [valid-type]
 generics_paramspec_basic.py:23: note: You can use ParamSpec as the first argument to Callable, e.g., "Callable[P, int]"
 generics_paramspec_basic.py:27: error: Invalid location for Concatenate  [valid-type]
@@ -15,7 +17,6 @@ generics_paramspec_basic.py:35: note: You can use ParamSpec as the first argumen
 generics_paramspec_basic.py:39: error: Invalid location for ParamSpec "P"  [valid-type]
 generics_paramspec_basic.py:39: note: You can use ParamSpec as the first argument to Callable, e.g., "Callable[P, int]"
 """
-conformance_automated = "Fail"
+conformance_automated = "Pass"
 errors_diff = """
-Line 15: Expected 1 errors
 """
diff --git a/conformance/results/mypy/version.toml b/conformance/results/mypy/version.toml
index 699a899..61bb190 100644
--- a/conformance/results/mypy/version.toml
+++ b/conformance/results/mypy/version.toml
@@ -1,2 +1,2 @@
-version = "mypy 1.14.0+dev.21587f01045246a9ecb54a054a5ba03e20cbbd19"
-test_duration = 4.5
+version = "mypy 1.14.0+dev.bf422add81d770eb4896b84afe800da48dbb21f1"
+test_duration = 5.0

Copy link
Contributor

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

Copy link
Collaborator

@hauntsaninja hauntsaninja 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!

@hauntsaninja hauntsaninja merged commit eec8071 into python:master Nov 20, 2024
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants