summaryrefslogtreecommitdiff
path: root/pylint/checkers/utils.py
diff options
context:
space:
mode:
authorRam Rachum <ram@rachum.com>2020-06-16 20:06:08 +0300
committerClaudiu Popa <pcmanticore@gmail.com>2020-06-22 08:11:51 +0200
commita73585740398052ccd6c67d33869d9049a27e8c7 (patch)
tree49b04549cbe32ca9856eb1d6f7964a061c6f9b08 /pylint/checkers/utils.py
parent35f838fc333f6bc55e0cbfd67da07785e91a51c0 (diff)
downloadpylint-git-a73585740398052ccd6c67d33869d9049a27e8c7.tar.gz
Add rule raise-missing-from
Diffstat (limited to 'pylint/checkers/utils.py')
-rw-r--r--pylint/checkers/utils.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/pylint/checkers/utils.py b/pylint/checkers/utils.py
index 941b0f69b..ed2c1478c 100644
--- a/pylint/checkers/utils.py
+++ b/pylint/checkers/utils.py
@@ -859,6 +859,24 @@ def find_try_except_wrapper_node(
return None
+def find_except_wrapper_node_in_scope(
+ node: astroid.node_classes.NodeNG,
+) -> Optional[Union[astroid.ExceptHandler, astroid.TryExcept]]:
+ """Return the ExceptHandler in which the node is, without going out of scope."""
+ current = node
+ while current.parent is not None:
+ current = current.parent
+ if isinstance(current, astroid.scoped_nodes.LocalsDictNodeNG):
+ # If we're inside a function/class definition, we don't want to keep checking
+ # higher ancestors for `except` clauses, because if these exist, it means our
+ # function/class was defined in an `except` clause, rather than the current code
+ # actually running in an `except` clause.
+ return None
+ if isinstance(current, astroid.ExceptHandler):
+ return current
+ return None
+
+
def is_from_fallback_block(node: astroid.node_classes.NodeNG) -> bool:
"""Check if the given node is from a fallback import block."""
context = find_try_except_wrapper_node(node)