From 4479b866ffbb5ea5b45123aebad1f9dfc7766b29 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Thu, 20 Jun 2019 19:49:09 +0200 Subject: [PATCH] CompiledContext should not have a file --- jedi/api/classes.py | 13 +++++++------ test/test_api/test_classes.py | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/jedi/api/classes.py b/jedi/api/classes.py index fb3cedac..8865c411 100644 --- a/jedi/api/classes.py +++ b/jedi/api/classes.py @@ -77,12 +77,13 @@ class BaseDefinition(object): @property def module_path(self): """Shows the file path of a module. e.g. ``/usr/lib/python2.7/os.py``""" - try: - py__file__ = self._get_module().py__file__ - except AttributeError: - return None - else: - return py__file__() + module = self._get_module() + if module.is_stub() or not module.is_compiled(): + # Compiled modules should not return a module path even if they + # have one. + return self._get_module().py__file__() + + return None @property def name(self): diff --git a/test/test_api/test_classes.py b/test/test_api/test_classes.py index b0cf2432..d2cb5bc3 100644 --- a/test/test_api/test_classes.py +++ b/test/test_api/test_classes.py @@ -9,6 +9,7 @@ import pytest import jedi from jedi import __doc__ as jedi_doc, names from ..helpers import TestCase +from jedi.evaluate.compiled import CompiledContextName def test_is_keyword(Script): @@ -439,3 +440,18 @@ def test_added_equals_to_params(Script): assert run(' bar').complete == '' x = run('foo(bar=isins').name_with_symbols assert x == 'isinstance' + + +def test_builtin_module_with_path(Script): + """ + This test simply tests if a module from /usr/lib/python3.8/lib-dynload/ has + a path or not. It shouldn't have a module_path, because that is just + confusing. + """ + semlock, = Script('from _multiprocessing import SemLock').goto_definitions() + assert isinstance(semlock._name, CompiledContextName) + assert semlock.module_path is None + assert semlock.in_builtin_module() is True + assert semlock.name == 'SemLock' + assert semlock.line is None + assert semlock.column is None