From fd435a7bbbd8b326aaf37d029a1ea0b661f58173 Mon Sep 17 00:00:00 2001 From: Leo Ryu <33325550+Leo-Ryu@users.noreply.github.com> Date: Sat, 12 Dec 2020 03:13:31 -0800 Subject: [PATCH] Check if string_names is None before returning string_names (#1708) * Check if string is None before using string_names * Add test asserting None string_names returns an empty list * Remove whitespace to pass flake8 * Add name to authors.txt Co-authored-by: Leo Ryu --- AUTHORS.txt | 1 + jedi/inference/value/module.py | 3 +++ test/test_inference/test_imports.py | 3 +++ 3 files changed, 7 insertions(+) diff --git a/AUTHORS.txt b/AUTHORS.txt index 6e881b7e1..6ffe9dfd6 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -60,6 +60,7 @@ Code Contributors - Max Mäusezahl (@mmaeusezahl) - Vladislav Serebrennikov (@endilll) - Andrii Kolomoiets (@muffinmad) +- Leo Ryu (@Leo-Ryu) And a few more "anonymous" contributors. diff --git a/jedi/inference/value/module.py b/jedi/inference/value/module.py index a5073b0ee..f076d72aa 100644 --- a/jedi/inference/value/module.py +++ b/jedi/inference/value/module.py @@ -179,6 +179,9 @@ def is_package(self): return self._is_package def py__package__(self): + if self.string_names is None: + return [] + if self._is_package: return self.string_names return self.string_names[:-1] diff --git a/test/test_inference/test_imports.py b/test/test_inference/test_imports.py index 8e49244f2..07ced3240 100644 --- a/test/test_inference/test_imports.py +++ b/test/test_inference/test_imports.py @@ -96,6 +96,9 @@ def test_correct_zip_package_behavior(Script, inference_state, environment, code if path is not None: assert value.py__path__() == [str(pkg_zip_path.joinpath(path))] + value.string_names = None + assert value.py__package__() == [] + def test_find_module_not_package_zipped(Script, inference_state, environment): path = get_example_dir('zipped_imports', 'not_pkg.zip')