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
8 changes: 4 additions & 4 deletions pyflakes/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ class AnnotationState:
NONE = 0
STRING = 1
BARE = 2
TYPE_ALIAS = 3
STR_AS_TYPE = 3


def in_annotation(func):
Expand Down Expand Up @@ -1070,7 +1070,7 @@ def handleNodeLoad(self, node, parent):
binding.is_lazy and
func_depth == 0 and (
self._in_annotation == AnnotationState.NONE or
self._in_annotation == AnnotationState.TYPE_ALIAS
self._in_annotation == AnnotationState.STR_AS_TYPE
)
):
self.report(messages.EagerUseOfLazyImport, node, name, binding.source)
Expand Down Expand Up @@ -1522,7 +1522,7 @@ def CALL(self, node):
self._handle_string_dot_format(node)

def _annotation(n: ast.AST) -> None:
with self._enter_annotation():
with self._enter_annotation(AnnotationState.STR_AS_TYPE):
self.handleNode(n, node)

def _annotations(nodes: list[ast.AST]) -> None:
Expand Down Expand Up @@ -2056,7 +2056,7 @@ def ANNASSIGN(self, node):
if node.value:
# If the annotation is `TypeAlias`, handle the *value* as an annotation.
if _is_typing(node.annotation, 'TypeAlias', self.scopeStack):
with self._enter_annotation(AnnotationState.TYPE_ALIAS):
with self._enter_annotation(AnnotationState.STR_AS_TYPE):
self.handleNode(node.value, node)
else:
self.handleNode(node.value, node)
Expand Down
7 changes: 7 additions & 0 deletions pyflakes/test/test_lazy_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,10 @@ def test_lazy_imports_eager_use_in_type_alias(self):
lazy from x import y
alias: TypeAlias = y # evaluated eagerly
''', m.EagerUseOfLazyImport)

def test_eager_use_in_TypeVar(self):
self.flakes('''
from typing import TypeVar
lazy from x import y
T = TypeVar("T", y)
''', m.EagerUseOfLazyImport)
Loading