3 Commits

Author SHA1 Message Date
maxalbert
69d203b60c Merge 383c596975 into 6aee460b1d 2025-01-19 23:27:59 +00:00
Maximilian Albert
383c596975 Fix crash (only convert __file__ attribute to a Path if it is not None) 2025-01-19 23:27:37 +00:00
Maximilian Albert
0ad565b95b Add second test for implicit namespace package with subpackages (but direct import statement) 2025-01-19 23:22:14 +00:00
2 changed files with 21 additions and 2 deletions

View File

@@ -183,10 +183,12 @@ class DirectObjectAccess:
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 ''

View File

@@ -593,7 +593,7 @@ def test_dict_completion(code, column, expected):
assert [c.complete for c in comps] == expected
def test_implicit_namespace_package_with_subpackages(monkeypatch):
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)
@@ -610,6 +610,23 @@ def test_implicit_namespace_package_with_subpackages(monkeypatch):
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']),