diff options
author | Angus L'Herrou <piraka@brandeis.edu> | 2021-10-05 18:44:29 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-05 18:44:29 -0400 |
commit | 13cad915e6b181b2f6a85efc2ead4856b23bccc0 (patch) | |
tree | 0b7346048016eef7168a1a95b1b851ccf649279a /pyflakes/checker.py | |
parent | cf75971656d9a04faa1b5aeaeb776da3567b8041 (diff) | |
download | pyflakes-13cad915e6b181b2f6a85efc2ead4856b23bccc0.tar.gz |
Detect typing module attributes with 'import typing as <name>' (#632)
* added functionality to detect typing module attributes with 'import typing as <name>'
* remove async keyword from test_aliased_import
Diffstat (limited to 'pyflakes/checker.py')
-rw-r--r-- | pyflakes/checker.py | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/pyflakes/checker.py b/pyflakes/checker.py index 6fafe89..45c7a4a 100644 --- a/pyflakes/checker.py +++ b/pyflakes/checker.py @@ -720,6 +720,16 @@ def _is_typing_helper(node, is_name_match_fn, scope_stack): return False + def _module_scope_is_typing(name): + for scope in reversed(scope_stack): + if name in scope: + return ( + isinstance(scope[name], Importation) and + scope[name].fullName in TYPING_MODULES + ) + + return False + return ( ( isinstance(node, ast.Name) and @@ -727,7 +737,7 @@ def _is_typing_helper(node, is_name_match_fn, scope_stack): ) or ( isinstance(node, ast.Attribute) and isinstance(node.value, ast.Name) and - node.value.id in TYPING_MODULES and + _module_scope_is_typing(node.value.id) and is_name_match_fn(node.attr) ) ) |