From b418e54f3b7842766b4f6cedbecc01e2d1cb750f Mon Sep 17 00:00:00 2001
From: jace-ys <jacetan@monzo.com>
Date: Fri, 21 Oct 2022 01:07:26 +0100
Subject: [PATCH 1/4] Handle distribution.files being None

---
 src/poetry/utils/env.py | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/poetry/utils/env.py b/src/poetry/utils/env.py
index 7de0d60d2bc..0a985ceef0d 100644
--- a/src/poetry/utils/env.py
+++ b/src/poetry/utils/env.py
@@ -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]
@@ -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]
@@ -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]
                 )

From 050dad8c05c7b3c8a8706624bdbedd4cb9dc6569 Mon Sep 17 00:00:00 2001
From: jace-ys <jacetan@monzo.com>
Date: Mon, 24 Oct 2022 16:10:19 +0100
Subject: [PATCH 2/4] Use break to fail-fast

---
 src/poetry/utils/env.py | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/src/poetry/utils/env.py b/src/poetry/utils/env.py
index 0a985ceef0d..f07f94fa4d5 100644
--- a/src/poetry/utils/env.py
+++ b/src/poetry/utils/env.py
@@ -328,8 +328,10 @@ def find_distribution_files_with_suffix(
         for distribution in self.distributions(
             name=distribution_name, writable_only=writable_only
         ):
-            files = [] if distribution.files is None else distribution.files
-            for file in files:
+            if not distribution.files:
+                break
+
+            for file in distribution.files:
                 if file.name.endswith(suffix):
                     yield Path(
                         distribution.locate_file(file),  # type: ignore[no-untyped-call]
@@ -341,8 +343,10 @@ def find_distribution_files_with_name(
         for distribution in self.distributions(
             name=distribution_name, writable_only=writable_only
         ):
-            files = [] if distribution.files is None else distribution.files
-            for file in files:
+            if not distribution.files:
+                break
+
+            for file in distribution.files:
                 if file.name == name:
                     yield Path(
                         distribution.locate_file(file),  # type: ignore[no-untyped-call]
@@ -372,8 +376,10 @@ def remove_distribution_files(self, distribution_name: str) -> list[Path]:
         for distribution in self.distributions(
             name=distribution_name, writable_only=True
         ):
-            files = [] if distribution.files is None else distribution.files
-            for file in files:
+            if not distribution.files:
+                break
+
+            for file in distribution.files:
                 path = Path(
                     distribution.locate_file(file),  # type: ignore[no-untyped-call]
                 )

From 419239431f0d0fd0fd483020523161d1bd48b878 Mon Sep 17 00:00:00 2001
From: jace-ys <jacetan@monzo.com>
Date: Mon, 24 Oct 2022 16:56:57 +0100
Subject: [PATCH 3/4] Use continue, not break

---
 src/poetry/utils/env.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/poetry/utils/env.py b/src/poetry/utils/env.py
index f07f94fa4d5..85137b39d9c 100644
--- a/src/poetry/utils/env.py
+++ b/src/poetry/utils/env.py
@@ -329,7 +329,7 @@ def find_distribution_files_with_suffix(
             name=distribution_name, writable_only=writable_only
         ):
             if not distribution.files:
-                break
+                continue
 
             for file in distribution.files:
                 if file.name.endswith(suffix):
@@ -344,7 +344,7 @@ def find_distribution_files_with_name(
             name=distribution_name, writable_only=writable_only
         ):
             if not distribution.files:
-                break
+                continue
 
             for file in distribution.files:
                 if file.name == name:
@@ -377,7 +377,7 @@ def remove_distribution_files(self, distribution_name: str) -> list[Path]:
             name=distribution_name, writable_only=True
         ):
             if not distribution.files:
-                break
+                continue
 
             for file in distribution.files:
                 path = Path(

From d78ba982830f562a0ee0ffd6a8035639fb703229 Mon Sep 17 00:00:00 2001
From: jace-ys <jacetan@monzo.com>
Date: Tue, 25 Oct 2022 22:04:41 +0100
Subject: [PATCH 4/4] Revert to original version

---
 src/poetry/utils/env.py | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/src/poetry/utils/env.py b/src/poetry/utils/env.py
index 85137b39d9c..0a985ceef0d 100644
--- a/src/poetry/utils/env.py
+++ b/src/poetry/utils/env.py
@@ -328,10 +328,8 @@ def find_distribution_files_with_suffix(
         for distribution in self.distributions(
             name=distribution_name, writable_only=writable_only
         ):
-            if not distribution.files:
-                continue
-
-            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]
@@ -343,10 +341,8 @@ def find_distribution_files_with_name(
         for distribution in self.distributions(
             name=distribution_name, writable_only=writable_only
         ):
-            if not distribution.files:
-                continue
-
-            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]
@@ -376,10 +372,8 @@ def remove_distribution_files(self, distribution_name: str) -> list[Path]:
         for distribution in self.distributions(
             name=distribution_name, writable_only=True
         ):
-            if not distribution.files:
-                continue
-
-            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]
                 )
