Skip to content

Commit 074a015

Browse files
committed
Refactor
1 parent 3944fa7 commit 074a015

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

bpython/importcompletion.py

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def __init__(
8383
paths = sys.path
8484

8585
self.find_iterator = self.find_all_modules(
86-
(Path(p).resolve() if p else Path.cwd() for p in paths)
86+
Path(p).resolve() if p else Path.cwd() for p in paths
8787
)
8888

8989
def module_matches(self, cw: str, prefix: str = "") -> Set[str]:
@@ -120,7 +120,7 @@ def attr_matches(
120120
matches = {
121121
name for name in dir(module) if name.startswith(name_after_dot)
122122
}
123-
module_part, _, _ = cw.rpartition(".")
123+
module_part = cw.rpartition(".")[0]
124124
if module_part:
125125
matches = {f"{module_part}.{m}" for m in matches}
126126

@@ -208,36 +208,35 @@ def find_modules(self, path: Path) -> Generator[Optional[str], None, None]:
208208
if name == "badsyntax_pep3120":
209209
# Workaround for issue #166
210210
continue
211+
212+
package_pathname = None
211213
try:
212-
package_pathname = None
213214
with warnings.catch_warnings():
214215
warnings.simplefilter("ignore", ImportWarning)
215216
spec = finder.find_spec(name)
216217
if spec is None:
217218
continue
218219
if spec.submodule_search_locations is not None:
219220
package_pathname = spec.submodule_search_locations[0]
220-
except (ImportError, OSError, SyntaxError):
221-
continue
222-
except UnicodeEncodeError:
223-
# Happens with Python 3 when there is a filename in some invalid encoding
221+
except (ImportError, OSError, SyntaxError, UnicodeEncodeError):
222+
# UnicodeEncodeError happens with Python 3 when there is a filename in some invalid encoding
224223
continue
225-
else:
226-
if package_pathname is not None:
227-
path_real = Path(package_pathname).resolve()
228-
try:
229-
stat = path_real.stat()
230-
except OSError:
231-
continue
232-
loaded_inode = _LoadedInode(stat.st_dev, stat.st_ino)
233-
if loaded_inode not in self.paths:
234-
self.paths.add(loaded_inode)
235-
for subname in self.find_modules(path_real):
236-
if subname is None:
237-
yield None # take a break to avoid unresponsiveness
238-
elif subname != "__init__":
239-
yield f"{name}.{subname}"
240-
yield name
224+
225+
if package_pathname is not None:
226+
path_real = Path(package_pathname).resolve()
227+
try:
228+
stat = path_real.stat()
229+
except OSError:
230+
continue
231+
loaded_inode = _LoadedInode(stat.st_dev, stat.st_ino)
232+
if loaded_inode not in self.paths:
233+
self.paths.add(loaded_inode)
234+
for subname in self.find_modules(path_real):
235+
if subname is None:
236+
yield None # take a break to avoid unresponsiveness
237+
elif subname != "__init__":
238+
yield f"{name}.{subname}"
239+
yield name
241240
yield None # take a break to avoid unresponsiveness
242241

243242
def find_all_modules(

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy