diff --git a/jedi/evaluate/helpers.py b/jedi/evaluate/helpers.py index c94a1fbe..497b81c6 100644 --- a/jedi/evaluate/helpers.py +++ b/jedi/evaluate/helpers.py @@ -172,7 +172,7 @@ def get_module_names(module, all_scopes): # parent_scope. There's None as a parent, because nodes in the module # node have the parent module and not suite as all the others. # Therefore it's important to catch that case. - names = [n for n in names if get_parent_scope(n).parent in (module, None)] + names = [n for n in names if get_parent_scope(n) == module] return names diff --git a/jedi/evaluate/syntax_tree.py b/jedi/evaluate/syntax_tree.py index 2b90a29a..5a2d5dc8 100644 --- a/jedi/evaluate/syntax_tree.py +++ b/jedi/evaluate/syntax_tree.py @@ -527,8 +527,6 @@ def tree_name_to_contexts(evaluator, context, tree_name): # which means the function itself. filters = [next(filters)] return finder.find(filters, attribute_lookup=False) - elif node.type == 'param': - raise NotImplementedError elif node.type not in ('import_from', 'import_name'): context = evaluator.create_context(context, tree_name) return eval_atom(context, tree_name) @@ -571,6 +569,8 @@ def tree_name_to_contexts(evaluator, context, tree_name): # the static analysis report. exceptions = context.eval_node(tree_name.get_previous_sibling().get_previous_sibling()) types = exceptions.execute_evaluated() + elif node.type == 'param': + types = NO_CONTEXTS else: raise ValueError("Should not happen. type: %s" % typ) return types diff --git a/jedi/parser_utils.py b/jedi/parser_utils.py index 212d70f2..2ee67f04 100644 --- a/jedi/parser_utils.py +++ b/jedi/parser_utils.py @@ -243,6 +243,9 @@ def get_parent_scope(node, include_flows=False): Returns the underlying scope. """ scope = node.parent + if scope.type in ('funcdef', 'classdef') and scope.name == node: + scope = scope.parent + while scope is not None: if include_flows and isinstance(scope, tree.Flow): return scope diff --git a/test/test_api/test_defined_names.py b/test/test_api/test_defined_names.py index ed5f1eb2..4df1181f 100644 --- a/test/test_api/test_defined_names.py +++ b/test/test_api/test_defined_names.py @@ -101,3 +101,20 @@ def test_names_twice(environment): def test_simple_name(environment): defs = names('foo', references=True, environment=environment) assert not defs[0]._name.infer() + + +def test_no_error(environment): + code = dedent(""" + def foo(a, b): + if a == 10: + if b is None: + print("foo") + a = 20 + """) + func_name, = names(code) + print(func_name.defined_names()) + a, b, a20 = func_name.defined_names() + assert a.name == 'a' + assert b.name == 'b' + assert a20.name == 'a' + assert a20.goto_assignments() == [a20]