Skip to content

Commit

Permalink
Fixes crash on subclassing Annotated without args, refs python#11808 (
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolevn authored and tushar-deepsource committed Jan 20, 2022
1 parent f11b331 commit f86759e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion mypy/typeanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1291,7 +1291,9 @@ def visit_unbound_type(self, t: UnboundType) -> TypeVarLikeList:
return []
elif node and node.fullname in ('typing_extensions.Literal', 'typing.Literal'):
return []
elif node and node.fullname in ('typing_extensions.Annotated', 'typing.Annotated'):
elif (node
and node.fullname in ('typing_extensions.Annotated', 'typing.Annotated')
and t.args):
# Don't query the second argument to Annotated for TypeVars
return self.query_types([t.args[0]])
else:
Expand Down
7 changes: 7 additions & 0 deletions test-data/unit/semanal-errors.test
Original file line number Diff line number Diff line change
Expand Up @@ -1435,3 +1435,10 @@ TP = ParamSpec('?') # E: String argument 1 "?" to ParamSpec(...) does not match
TP2: int = ParamSpec('TP2') # E: Cannot declare the type of a parameter specification

[out]


[case testBaseClassAnnotatedWithoutArgs]
# https://github.com/python/mypy/issues/11808
from typing_extensions import Annotated
# Nest line should not crash:
class A(Annotated): pass # E: Annotated[...] must have exactly one type argument and at least one annotation

0 comments on commit f86759e

Please sign in to comment.