From e7528198d3846b7abffaafff0ed36161c277f281 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Sun, 13 Sep 2015 23:28:14 +0200 Subject: [PATCH] Fix an issue with raise statements in the linter. --- jedi/api/__init__.py | 2 +- jedi/evaluate/analysis.py | 10 +++------- test/static_analysis/keywords.py | 7 +++++++ 3 files changed, 11 insertions(+), 8 deletions(-) create mode 100644 test/static_analysis/keywords.py diff --git a/jedi/api/__init__.py b/jedi/api/__init__.py index a5b0b109..e2371463 100644 --- a/jedi/api/__init__.py +++ b/jedi/api/__init__.py @@ -536,7 +536,7 @@ class Script(object): #statements = set(chain(*self._parser.module().used_names.values())) nodes, imp_names, decorated_funcs = \ - analysis.get_module_statements(self._parser.module()) + analysis.get_executable_nodes(self._parser.module()) # Sort the statements so that the results are reproducible. for n in imp_names: imports.ImportWrapper(self._evaluator, n).follow() diff --git a/jedi/evaluate/analysis.py b/jedi/evaluate/analysis.py index d4a411f4..27b34a95 100644 --- a/jedi/evaluate/analysis.py +++ b/jedi/evaluate/analysis.py @@ -210,9 +210,9 @@ def _check_for_exception_catch(evaluator, jedi_obj, exception, payload=None): return False -def get_module_statements(module): +def get_executable_nodes(module): """ - Returns the statements used in a module. All these statements should be + Returns the nodes used in a module. All these nodes should be evaluated to check for potential exceptions. """ def check_children(node): @@ -251,7 +251,7 @@ def get_module_statements(module): new |= add_nodes(children) elif node.type in ('simple_stmt', 'suite'): new |= add_nodes(node.children) - elif node.type in ('return_stmt', 'yield_expr'): + elif node.type in ('return_stmt', 'yield_expr', 'raise_stmt'): try: new.add(node.children[1]) except IndexError: @@ -259,8 +259,6 @@ def get_module_statements(module): elif node.type not in ('whitespace', 'operator', 'keyword', 'parameters', 'decorated', 'except_clause') \ and not isinstance(node, (tree.ClassOrFunc, tree.Import)): - new.add(node) - try: children = node.children except AttributeError: @@ -268,8 +266,6 @@ def get_module_statements(module): else: for next_node in children: new.update(check_children(node)) - if next_node.type != 'keyword' and node.type != 'expr_stmt': - new.add(node) return new nodes = set() diff --git a/test/static_analysis/keywords.py b/test/static_analysis/keywords.py new file mode 100644 index 00000000..e3fcaa43 --- /dev/null +++ b/test/static_analysis/keywords.py @@ -0,0 +1,7 @@ +def raises(): + raise KeyError() + + +def wrong_name(): + #! 6 name-error + raise NotExistingException()