@@ -168,19 +168,31 @@ def find_module(self, id: str) -> ModuleSearchResult:
168
168
169
169
def _find_module_non_stub_helper (self , components : List [str ],
170
170
pkg_dir : str ) -> Union [OnePackageDir , ModuleNotFoundReason ]:
171
- plausible_match = False
171
+ plausible_match = None # type: Optional[Tuple[str, OnePackageDir]]
172
+ plausible_match_is_ns = False
172
173
dir_path = pkg_dir
173
174
for index , component in enumerate (components ):
174
175
dir_path = os .path .join (dir_path , component )
175
176
if self .fscache .isfile (os .path .join (dir_path , 'py.typed' )):
176
177
return os .path .join (pkg_dir , * components [:- 1 ]), index == 0
177
- elif not plausible_match and (self .fscache .isdir (dir_path )
178
- or self .fscache .isfile (dir_path + ".py" )):
179
- plausible_match = True
180
- if plausible_match :
181
- return ModuleNotFoundReason .FOUND_WITHOUT_TYPE_HINTS
182
- else :
178
+ if not plausible_match or plausible_match_is_ns :
179
+ have_package_or_mod = self .fscache .isfile (os .path .join (dir_path , '__init__.py' )) \
180
+ or self .fscache .isfile (dir_path + ".py" )
181
+ if not have_package_or_mod :
182
+ have_ns_package = self .fscache .isdir (dir_path )
183
+
184
+ if have_package_or_mod or (not plausible_match_is_ns and have_ns_package ):
185
+ plausible_match = (
186
+ '.' .join (components [:(index + 1 )]),
187
+ (os .path .join (pkg_dir , * components [:- 1 ]), index == 0 )
188
+ )
189
+ plausible_match_is_ns = not have_package_or_mod
190
+ if not plausible_match :
183
191
return ModuleNotFoundReason .NOT_FOUND
192
+ elif self .options and plausible_match [0 ] in self .options .pep561_override :
193
+ return plausible_match [1 ]
194
+ else :
195
+ return ModuleNotFoundReason .FOUND_WITHOUT_TYPE_HINTS
184
196
185
197
def _update_ns_ancestors (self , components : List [str ], match : Tuple [str , bool ]) -> None :
186
198
path , verify = match
0 commit comments