forked from VimPlug/jedi
Fix an issue with raise statements in the linter.
This commit is contained in:
@@ -536,7 +536,7 @@ class Script(object):
|
|||||||
|
|
||||||
#statements = set(chain(*self._parser.module().used_names.values()))
|
#statements = set(chain(*self._parser.module().used_names.values()))
|
||||||
nodes, imp_names, decorated_funcs = \
|
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.
|
# Sort the statements so that the results are reproducible.
|
||||||
for n in imp_names:
|
for n in imp_names:
|
||||||
imports.ImportWrapper(self._evaluator, n).follow()
|
imports.ImportWrapper(self._evaluator, n).follow()
|
||||||
|
|||||||
@@ -210,9 +210,9 @@ def _check_for_exception_catch(evaluator, jedi_obj, exception, payload=None):
|
|||||||
return False
|
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.
|
evaluated to check for potential exceptions.
|
||||||
"""
|
"""
|
||||||
def check_children(node):
|
def check_children(node):
|
||||||
@@ -251,7 +251,7 @@ def get_module_statements(module):
|
|||||||
new |= add_nodes(children)
|
new |= add_nodes(children)
|
||||||
elif node.type in ('simple_stmt', 'suite'):
|
elif node.type in ('simple_stmt', 'suite'):
|
||||||
new |= add_nodes(node.children)
|
new |= add_nodes(node.children)
|
||||||
elif node.type in ('return_stmt', 'yield_expr'):
|
elif node.type in ('return_stmt', 'yield_expr', 'raise_stmt'):
|
||||||
try:
|
try:
|
||||||
new.add(node.children[1])
|
new.add(node.children[1])
|
||||||
except IndexError:
|
except IndexError:
|
||||||
@@ -259,8 +259,6 @@ def get_module_statements(module):
|
|||||||
elif node.type not in ('whitespace', 'operator', 'keyword',
|
elif node.type not in ('whitespace', 'operator', 'keyword',
|
||||||
'parameters', 'decorated', 'except_clause') \
|
'parameters', 'decorated', 'except_clause') \
|
||||||
and not isinstance(node, (tree.ClassOrFunc, tree.Import)):
|
and not isinstance(node, (tree.ClassOrFunc, tree.Import)):
|
||||||
new.add(node)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
children = node.children
|
children = node.children
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
@@ -268,8 +266,6 @@ def get_module_statements(module):
|
|||||||
else:
|
else:
|
||||||
for next_node in children:
|
for next_node in children:
|
||||||
new.update(check_children(node))
|
new.update(check_children(node))
|
||||||
if next_node.type != 'keyword' and node.type != 'expr_stmt':
|
|
||||||
new.add(node)
|
|
||||||
return new
|
return new
|
||||||
|
|
||||||
nodes = set()
|
nodes = set()
|
||||||
|
|||||||
7
test/static_analysis/keywords.py
Normal file
7
test/static_analysis/keywords.py
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
def raises():
|
||||||
|
raise KeyError()
|
||||||
|
|
||||||
|
|
||||||
|
def wrong_name():
|
||||||
|
#! 6 name-error
|
||||||
|
raise NotExistingException()
|
||||||
Reference in New Issue
Block a user