@@ -83,7 +83,7 @@ def __init__(
83
83
paths = sys .path
84
84
85
85
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
87
87
)
88
88
89
89
def module_matches (self , cw : str , prefix : str = "" ) -> Set [str ]:
@@ -120,7 +120,7 @@ def attr_matches(
120
120
matches = {
121
121
name for name in dir (module ) if name .startswith (name_after_dot )
122
122
}
123
- module_part , _ , _ = cw .rpartition ("." )
123
+ module_part = cw .rpartition ("." )[ 0 ]
124
124
if module_part :
125
125
matches = {f"{ module_part } .{ m } " for m in matches }
126
126
@@ -208,36 +208,35 @@ def find_modules(self, path: Path) -> Generator[Optional[str], None, None]:
208
208
if name == "badsyntax_pep3120" :
209
209
# Workaround for issue #166
210
210
continue
211
+
212
+ package_pathname = None
211
213
try :
212
- package_pathname = None
213
214
with warnings .catch_warnings ():
214
215
warnings .simplefilter ("ignore" , ImportWarning )
215
216
spec = finder .find_spec (name )
216
217
if spec is None :
217
218
continue
218
219
if spec .submodule_search_locations is not None :
219
220
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
224
223
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
241
240
yield None # take a break to avoid unresponsiveness
242
241
243
242
def find_all_modules (
0 commit comments