Skip to content

Commit

Permalink
fix: handle distribution.files being None (#6877)
Browse files Browse the repository at this point in the history
We discovered that in some unknown situations, `distribution.files` can
be `None`, causing the assertion to fail. To handle `distribution.files`
being `None` more gracefully, we treat it as if it were an empty list.

Resolves: #6788
  • Loading branch information
jace-ys committed Nov 3, 2022
1 parent 0dc3d54 commit 18c2903
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/poetry/utils/env.py
Expand Up @@ -328,8 +328,8 @@ def find_distribution_files_with_suffix(
for distribution in self.distributions(
name=distribution_name, writable_only=writable_only
):
assert distribution.files is not None
for file in distribution.files:
files = [] if distribution.files is None else distribution.files
for file in files:
if file.name.endswith(suffix):
yield Path(
distribution.locate_file(file), # type: ignore[no-untyped-call]
Expand All @@ -341,8 +341,8 @@ def find_distribution_files_with_name(
for distribution in self.distributions(
name=distribution_name, writable_only=writable_only
):
assert distribution.files is not None
for file in distribution.files:
files = [] if distribution.files is None else distribution.files
for file in files:
if file.name == name:
yield Path(
distribution.locate_file(file), # type: ignore[no-untyped-call]
Expand Down Expand Up @@ -372,8 +372,8 @@ def remove_distribution_files(self, distribution_name: str) -> list[Path]:
for distribution in self.distributions(
name=distribution_name, writable_only=True
):
assert distribution.files is not None
for file in distribution.files:
files = [] if distribution.files is None else distribution.files
for file in files:
path = Path(
distribution.locate_file(file), # type: ignore[no-untyped-call]
)
Expand Down

0 comments on commit 18c2903

Please sign in to comment.