diff --git a/jedi/evaluate/compiled/mixed.py b/jedi/evaluate/compiled/mixed.py index b8003502..773b5292 100644 --- a/jedi/evaluate/compiled/mixed.py +++ b/jedi/evaluate/compiled/mixed.py @@ -166,11 +166,10 @@ def _find_syntax_node_name(evaluator, access_handle): return None # It's too hard to find lambdas. # Doesn't always work (e.g. os.stat_result) - try: - names = module_node.get_used_names()[name_str] - except KeyError: - return None + names = module_node.get_used_names().get(name_str, []) names = [n for n in names if n.is_definition()] + if not names: + return None try: code = python_object.__code__ diff --git a/test/test_api/test_interpreter.py b/test/test_api/test_interpreter.py index 0dfbd1ac..b1ca24bb 100644 --- a/test/test_api/test_interpreter.py +++ b/test/test_api/test_interpreter.py @@ -341,3 +341,18 @@ def test_dir_magic_method(): foo = [c for c in completions if c.name == 'foo'][0] assert foo._goto_definitions() == [] + + +def test_name_not_findable(): + class X(): + if 0: + NOT_FINDABLE + + def hidden(self): + return + + hidden.__name__ = 'NOT_FINDABLE' + + setattr(X, 'NOT_FINDABLE', X.hidden) + + assert jedi.Interpreter("X.NOT_FINDA", [locals()]).completions()