diff --git a/jedi/api/classes.py b/jedi/api/classes.py index 3be20172..5b97d743 100644 --- a/jedi/api/classes.py +++ b/jedi/api/classes.py @@ -161,9 +161,17 @@ class BaseDefinition(object): pass if name.api_type == 'module': - module_context, = name.infer() - for n in reversed(module_context.py__name__().split('.')): - yield n + module_contexts = name.infer() + if module_contexts: + module_context, = module_contexts + for n in reversed(module_context.py__name__().split('.')): + yield n + else: + # We don't really know anything about the path here. This + # module is just an import that would lead in an + # ImportError. So simply return the name. + yield name.string_name + return else: yield name.string_name diff --git a/test/test_api/test_full_name.py b/test/test_api/test_full_name.py index 0c258245..d2ad9d02 100644 --- a/test/test_api/test_full_name.py +++ b/test/test_api/test_full_name.py @@ -96,3 +96,9 @@ def test_os_path(): assert d.full_name == 'os.path.join' d, = jedi.Script('import os.p').completions() assert d.full_name == 'os.path' + + +def test_os_issues(): + """Issue #873""" + c, = jedi.Script('import os\nos.nt''').completions() + assert c.full_name == 'nt'