Disallow no-args generic aliases when using PEP 613 explicit aliases#18173
Merged
JukkaL merged 4 commits intopython:masterfrom Dec 20, 2024
Merged
Disallow no-args generic aliases when using PEP 613 explicit aliases#18173JukkaL merged 4 commits intopython:masterfrom
JukkaL merged 4 commits intopython:masterfrom
Conversation
Collaborator
Author
|
Conformance results diff for this PR ( diff --git a/conformance/results/mypy/aliases_explicit.toml b/conformance/results/mypy/aliases_explicit.toml
index ee05762..f07e7ad 100644
--- a/conformance/results/mypy/aliases_explicit.toml
+++ b/conformance/results/mypy/aliases_explicit.toml
@@ -24,11 +24,11 @@ aliases_explicit.py:89: error: Invalid type: try using Literal[1] instead? [val
aliases_explicit.py:90: error: Invalid type alias: expression is not a valid type [valid-type]
aliases_explicit.py:90: error: Function "list" could always be true in boolean context [truthy-function]
aliases_explicit.py:91: error: Invalid type alias: expression is not a valid type [valid-type]
+aliases_explicit.py:100: error: Bad number of arguments for type alias, expected 0, given 1 [type-arg]
aliases_explicit.py:101: error: "UnionType[list[Any], set[Any]]" not callable [operator]
aliases_explicit.py:102: error: Bad number of arguments for type alias, expected 0, given 1 [type-arg]
"""
-conformance_automated = "Fail"
+conformance_automated = "Pass"
errors_diff = """
-Line 100: Expected 1 errors
"""
ignore_errors = ["Function \"list\" could always be true in boolean context"]
diff --git a/conformance/results/mypy/version.toml b/conformance/results/mypy/version.toml
index 699a899..1d9b711 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.6563c362fd5ee8e1fbf17775eab5dcad5a0a7459"
+test_duration = 5.1 |
This comment has been minimized.
This comment has been minimized.
This is expected, now that the below branch is no longer taken for PEP 613 aliases. Implicit aliases are now the only case with eager expansion. https://github.com/python/mypy/blob/21587f01045246a9ecb54a054a5ba03e20cbbd19/mypy/typeanal.py#L2147-L2151
This comment has been minimized.
This comment has been minimized.
Collaborator
Author
|
The psycopg hits are true positives from aliases of the form |
JukkaL
reviewed
Nov 21, 2024
Contributor
|
Diff from mypy_primer, showing the effect of this PR on open source code: psycopg (https://github.com/psycopg/psycopg)
+ psycopg/psycopg/_acompat.py:43: error: Bad number of arguments for type alias, expected 0, given 1 [type-arg]
+ psycopg/psycopg/_acompat.py:52: error: Returning Any from function declared to return "T" [no-any-return]
+ psycopg/psycopg/_acompat.py:55: error: Bad number of arguments for type alias, expected 0, given 1 [type-arg]
+ psycopg_pool/psycopg_pool/_acompat.py:63: error: Bad number of arguments for type alias, expected 0, given 1 [type-arg]
+ psycopg_pool/psycopg_pool/_acompat.py:72: error: Returning Any from function declared to return "T" [no-any-return]
+ psycopg_pool/psycopg_pool/_acompat.py:105: error: Bad number of arguments for type alias, expected 0, given 1 [type-arg]
|
JukkaL
approved these changes
Dec 20, 2024
hauntsaninja
added a commit
to hauntsaninja/mypy
that referenced
this pull request
Jan 23, 2025
This is a partial revert of python#18173 to unblock the 1.15 release Fixes python#18488
hauntsaninja
added a commit
that referenced
this pull request
Jan 23, 2025
wesleywright
pushed a commit
that referenced
this pull request
Jan 23, 2025
x612skm
pushed a commit
to x612skm/mypy-dev
that referenced
this pull request
Feb 24, 2025
This is a partial revert of python#18173 to unblock the 1.15 release Fixes python#18488
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Per the type system conformance tests, this is ok:
While this is not:
Mypy currently permits both. This PR makes mypy reject the latter case, improving conformance.
As part of this, no-args PEP 613 explicit aliases are no longer eagerly expanded.
(Also removed a stale comment referencing
TypeAliasExpr.no_args, which was removed in #15924)