Skip to content

Commit

Permalink
Check if string_names is None before returning string_names (#1708)
Browse files Browse the repository at this point in the history
* 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 <leo@episci.com>
  • Loading branch information
Leo-Ryu and Leo Ryu committed Dec 12, 2020
1 parent 42a759a commit fd435a7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions AUTHORS.txt
Expand Up @@ -60,6 +60,7 @@ Code Contributors
- Max Mäusezahl (@mmaeusezahl) <maxmaeusezahl@googlemail.com>
- Vladislav Serebrennikov (@endilll)
- Andrii Kolomoiets (@muffinmad)
- Leo Ryu (@Leo-Ryu)

And a few more "anonymous" contributors.

Expand Down
3 changes: 3 additions & 0 deletions jedi/inference/value/module.py
Expand Up @@ -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]
Expand Down
3 changes: 3 additions & 0 deletions test/test_inference/test_imports.py
Expand Up @@ -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')
Expand Down

0 comments on commit fd435a7

Please sign in to comment.