Skip to content

Fix missing error when redeclaring type variable in nested generic class #18883

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

brianschubert
Copy link
Collaborator

Closes #10479

Fixes a case where mypy doesn't warn about an inner generic class using a type variable by the same name as an outer generic class if the inner generic class doesn't declare the type variable using Generic, Protocol, or PEP-695 syntax.

@brianschubert
Copy link
Collaborator Author

Typing conformance diff for this PR (generics_scoping now passes 🎉):

diff --git a/conformance/results/mypy/generics_scoping.toml b/conformance/results/mypy/generics_scoping.toml
index d9be0a0..d588666 100644
--- a/conformance/results/mypy/generics_scoping.toml
+++ b/conformance/results/mypy/generics_scoping.toml
@@ -11,6 +11,7 @@ generics_scoping.py:54: error: Type variable "generics_scoping.S" is unbound  [v
 generics_scoping.py:54: note: (Hint: Use "Generic[S]" or "Protocol[S]" base class to bind "S" inside a class)
 generics_scoping.py:54: note: (Hint: Use "S" in function signature to bind "S" inside a function)
 generics_scoping.py:65: error: Free type variable expected in Generic[...]  [misc]
+generics_scoping.py:75: error: Type variable "T" is bound by an outer class  [valid-type]
 generics_scoping.py:78: error: Type variable "generics_scoping.T" is unbound  [valid-type]
 generics_scoping.py:78: note: (Hint: Use "Generic[T]" or "Protocol[T]" base class to bind "T" inside a class)
 generics_scoping.py:78: note: (Hint: Use "T" in function signature to bind "T" inside a function)
@@ -25,7 +26,6 @@ generics_scoping.py:96: error: Type variable "generics_scoping.T" is unbound  [v
 generics_scoping.py:96: note: (Hint: Use "Generic[T]" or "Protocol[T]" base class to bind "T" inside a class)
 generics_scoping.py:96: note: (Hint: Use "T" in function signature to bind "T" inside a function)
 """
-conformance_automated = "Fail"
+conformance_automated = "Pass"
 errors_diff = """
-Line 75: Expected 1 errors
 """
diff --git a/conformance/results/mypy/version.toml b/conformance/results/mypy/version.toml
index e3a8b6e..7162661 100644
--- a/conformance/results/mypy/version.toml
+++ b/conformance/results/mypy/version.toml
@@ -1,2 +1,2 @@
-version = "mypy 1.16.0+dev.e867132134c7b8046ebae2d6e1fa9fc184b9e9d7"
-test_duration = 4.9
+version = "mypy 1.16.0+dev.dd0f577f1caebfcd944fb247086af6150e6f1b02"
+test_duration = 5.3

Copy link
Contributor

github-actions bot commented Apr 5, 2025

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

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.

Error isn't provided when TypeVar is defined in both outer and inner class scopes
1 participant