Skip to content
Open
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
10 changes: 8 additions & 2 deletions pyflakes/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1372,10 +1372,16 @@ def ignore(self, node):
NAMEDEXPR = handleChildren

def SUBSCRIPT(self, node):
if _is_name_or_attr(node.value, 'Literal'):
if (
_is_typing(node.value, 'Literal', self.scopeStack)
or _is_name_or_attr(node.value, 'Literal')
):
with self._enter_annotation(AnnotationState.NONE):
self.handleChildren(node)
elif _is_name_or_attr(node.value, 'Annotated'):
elif (
_is_typing(node.value, 'Annotated', self.scopeStack)
or _is_name_or_attr(node.value, 'Annotated')
):
self.handleNode(node.value, node)

# py39+
Expand Down
26 changes: 26 additions & 0 deletions pyflakes/test/test_type_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,32 @@ def f(x: Literal['some string', 'foo bar']) -> None:
return None
""")

def test_annotated_type_typing_alias(self):
"""Annotated imported under an alias should not produce F821."""
self.flakes("""
from typing_extensions import Annotated as WithSchema

def f(x: WithSchema[int, 'hello']) -> None:
return None
""")

def test_annotated_type_typing_alias_forward_type(self):
self.flakes("""
from typing import Annotated as Ann

def f(x: Ann['integer', 1]) -> None:
return None
""", m.UndefinedName)

def test_literal_type_typing_alias(self):
"""Literal imported under an alias should not produce F821."""
self.flakes("""
from typing import Literal as Lit

def f(x: Lit['some string']) -> None:
return None
""")

def test_deferred_twice_annotation(self):
self.flakes("""
from queue import Queue
Expand Down