Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions pyflakes/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1551,6 +1551,14 @@ def _non_annotations(nodes: list[ast.AST]) -> None:
else:
_non_annotation(kwd)

elif _is_typing(node.func, 'assert_type', self.scopeStack):
_non_annotation(node.func)

# assert_type(val, "tp")
_non_annotations(node.args[:1])
_annotations(node.args[1:])
_non_annotations(node.keywords)

elif _is_typing(node.func, 'TypeVar', self.scopeStack):
_non_annotation(node.func)
_non_annotations(node.args[:1])
Expand All @@ -1565,6 +1573,34 @@ def _non_annotations(nodes: list[ast.AST]) -> None:
else:
_non_annotation(kwd)

elif (
_is_typing(node.func, 'ParamSpec', self.scopeStack) or
_is_typing(node.func, 'TypeVarTuple', self.scopeStack)
):
_non_annotation(node.func)
_non_annotations(node.args)

# ParamSpec("P", default=..., bound=...)
# TypeVarTuple("Ts", default=..., bound=...)
for kwd in node.keywords:
if kwd.arg in ('bound', 'default'):
_annotation(kwd)
else:
_non_annotation(kwd)

elif _is_typing(node.func, 'NewType', self.scopeStack):
_non_annotation(node.func)
_non_annotations(node.args[:1])

# NewType("NT", "C")
_annotations(node.args[1:])

for kwd in node.keywords:
if kwd.arg == 'tp':
_annotation(kwd)
else:
_non_annotation(kwd)

elif _is_typing(node.func, "TypedDict", self.scopeStack):
_non_annotation(node.func)
_non_annotations(node.args[:1])
Expand Down
29 changes: 29 additions & 0 deletions pyflakes/test/test_type_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,35 @@ def test_typevar_undefined_arg0(self):
T = TypeVar(T, int)
""", m.UndefinedName)

def test_newtype_quoted_types(self):
self.flakes("""
from typing import NewType
from u import C, D
NT1 = NewType("NT1", "C")
NT2 = NewType("NT2", tp="D")
""")

def test_typevartuple_quoted_types(self):
self.flakes("""
from typing import TypeVarTuple
from u import C, D
Ts = TypeVarTuple("Ts", default="C", bound="D")
""")

def test_paramspec_quoted_types(self):
self.flakes("""
from typing import ParamSpec
from u import C, D
P = ParamSpec("P", default="C", bound="D")
""")

def test_assert_type_quoted_types(self):
self.flakes("""
from typing import assert_type
from u import C
assert_type(1, "C")
""")

def test_literal_type_typing(self):
self.flakes("""
from typing import Literal
Expand Down
Loading