Skip to content

Commit 83ca33e

Browse files
Yield from import module discovery
Avoid interruptions by yielding more frequently. This prevent unresponsiveness while working through portions of directory trees without any Python modules.
1 parent a9db837 commit 83ca33e

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

bpython/importcompletion.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,9 @@ def complete(self, cursor_offset: int, line: str) -> Optional[Set[str]]:
155155
else:
156156
return None
157157

158-
def find_modules(self, path: Path) -> Generator[str, None, None]:
158+
def find_modules(
159+
self, path: Path
160+
) -> Generator[Union[str, None], None, None]:
159161
"""Find all modules (and packages) for a given directory."""
160162
if not path.is_dir():
161163
# Perhaps a zip file
@@ -219,9 +221,12 @@ def find_modules(self, path: Path) -> Generator[str, None, None]:
219221
if (stat.st_dev, stat.st_ino) not in self.paths:
220222
self.paths.add((stat.st_dev, stat.st_ino))
221223
for subname in self.find_modules(path_real):
222-
if subname != "__init__":
224+
if subname is None:
225+
yield None # take a break to avoid unresponsiveness
226+
elif subname != "__init__":
223227
yield f"{name}.{subname}"
224228
yield name
229+
yield None # take a break to avoid unresponsiveness
225230

226231
def find_all_modules(
227232
self, paths: Iterable[Path]
@@ -231,7 +236,8 @@ def find_all_modules(
231236

232237
for p in paths:
233238
for module in self.find_modules(p):
234-
self.modules.add(module)
239+
if module is not None:
240+
self.modules.add(module)
235241
yield
236242

237243
def find_coroutine(self) -> Optional[bool]:

0 commit comments

Comments
 (0)