Skip to content

Commit 18c2903

Browse files
authored
fix: handle distribution.files being None (#6877)
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
1 parent 0dc3d54 commit 18c2903

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/poetry/utils/env.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,8 @@ def find_distribution_files_with_suffix(
328328
for distribution in self.distributions(
329329
name=distribution_name, writable_only=writable_only
330330
):
331-
assert distribution.files is not None
332-
for file in distribution.files:
331+
files = [] if distribution.files is None else distribution.files
332+
for file in files:
333333
if file.name.endswith(suffix):
334334
yield Path(
335335
distribution.locate_file(file), # type: ignore[no-untyped-call]
@@ -341,8 +341,8 @@ def find_distribution_files_with_name(
341341
for distribution in self.distributions(
342342
name=distribution_name, writable_only=writable_only
343343
):
344-
assert distribution.files is not None
345-
for file in distribution.files:
344+
files = [] if distribution.files is None else distribution.files
345+
for file in files:
346346
if file.name == name:
347347
yield Path(
348348
distribution.locate_file(file), # type: ignore[no-untyped-call]
@@ -372,8 +372,8 @@ def remove_distribution_files(self, distribution_name: str) -> list[Path]:
372372
for distribution in self.distributions(
373373
name=distribution_name, writable_only=True
374374
):
375-
assert distribution.files is not None
376-
for file in distribution.files:
375+
files = [] if distribution.files is None else distribution.files
376+
for file in files:
377377
path = Path(
378378
distribution.locate_file(file), # type: ignore[no-untyped-call]
379379
)

0 commit comments

Comments
 (0)