You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[regression] isinstance complains about parametrized generics with any use of TypeAlias #18488
Any attempt to call isinstance with a variable annotated as a TypeAlias seems to result in the error message error: Parameterized generics cannot be used with class or instance checks, even if the aliased type is non-generic. mypy_primer points at #18173 as the breaking commit, but that PR seems to have been intended to deal with type aliases of generic types; it seems that we're treating allTypeAlias-based aliases as generic types, which AFAICT is broader than intended.
MyPy finds no errors, matching the runtime behavior. Pyright and mypy 1.4 both find no errors in my minimal example.
Actual Behavior
Per the playground link:
main.py:9: error: Parameterized generics cannot be used with class or instance checks [misc]
Found 1 error in 1 file (checked 1 source file)
Your Environment
I found this when dogfooding mypy master commit c4e2eb7 against Dropbox's internal Python repo, but mypy_primer also reproduces the same thing, as does mypy playground.
diff --git a/mypy/semanal.py b/mypy/semanal.py
index 034d8fb28..a92227d79 100644
--- a/mypy/semanal.py
+++ b/mypy/semanal.py
@@ -4022,7 +4022,7 @@ class SemanticAnalyzer(
and not res.args
and not empty_tuple_index
and not pep_695
- and not pep_613
+ # and not pep_613
)
if isinstance(res, ProperType) and isinstance(res, Instance):
if not validate_instance(res, self.fail, empty_tuple_index):
Would have to disable some of the new test cases, but the spec is maybe a little aggressive in disallowing that type alias
Activity
hauntsaninja commentedon Jan 19, 2025
cc @brianschubert in case you have time to take a look!
We could do e.g. the following to unblock
Would have to disable some of the new test cases, but the spec is maybe a little aggressive in disallowing that type alias
Fix isinstance with explicit (non generic) type alias
hauntsaninja commentedon Jan 23, 2025
Maybe we do this to unblock the release? #18512
Fix isinstance with explicit (non generic) type alias (python#18512)
Fix isinstance with explicit (non generic) type alias (#18512)
Fix isinstance with explicit (non generic) type alias (python#18512)