Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for #2044 #2045

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion jedi/inference/compiled/access.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,12 @@ def py__bool__(self):

def py__file__(self) -> Optional[Path]:
try:
return Path(self._obj.__file__)
__file__attribute = self._obj.__file__
except AttributeError:
return None

return Path(__file__attribute) if __file__attribute is not None else None

def py__doc__(self):
return inspect.getdoc(self._obj) or ''

Expand Down
36 changes: 36 additions & 0 deletions test/test_api/test_interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@

import jedi
import jedi.settings
from jedi import Project
from jedi.inference.compiled import mixed
from importlib import import_module
from test.helpers import get_example_dir


class _GlobalNameSpace:
Expand Down Expand Up @@ -591,6 +593,40 @@ class Inherited(dict):
assert [c.complete for c in comps] == expected


def test_implicit_namespace_package_with_subpackages_v1(monkeypatch):
sys_path_dir1 = get_example_dir('implicit_namespace_package_with_subpackages', 'ns1')
sys_path_dir2 = get_example_dir('implicit_namespace_package_with_subpackages', 'ns2')
monkeypatch.syspath_prepend(sys_path_dir1)
monkeypatch.syspath_prepend(sys_path_dir2)

import pkg_implicit_namespace_package_test
interpreter = jedi.Interpreter(
"pkg_implicit_namespace_package_test.",
namespaces=[locals()],
project=Project('.')
)
comps = interpreter.complete()
expected = ["pkgA", "pkgB"]
assert [c.complete for c in comps] == expected


def test_implicit_namespace_package_with_subpackages_v2(monkeypatch):
sys_path_dir1 = get_example_dir('implicit_namespace_package_with_subpackages', 'ns1')
sys_path_dir2 = get_example_dir('implicit_namespace_package_with_subpackages', 'ns2')
monkeypatch.syspath_prepend(sys_path_dir1)
monkeypatch.syspath_prepend(sys_path_dir2)

# import pkg_implicit_namespace_package_test
interpreter = jedi.Interpreter(
"import pkg_implicit_namespace_package_test.",
namespaces=[locals()],
project=Project('.')
)
comps = interpreter.complete()
expected = ["pkgA", "pkgB"]
assert [c.complete for c in comps] == expected


@pytest.mark.parametrize(
'code, types', [
('dct[1]', ['int']),
Expand Down
Loading