@@ -506,21 +506,24 @@ def _find_module(self, id: str, use_typeshed: bool) -> ModuleSearchResult:
506506 dir_prefix = base_dir
507507 for _ in range (len (components ) - 1 ):
508508 dir_prefix = os .path .dirname (dir_prefix )
509+
510+ # Stubs-only packages always take precedence over py.typed packages
511+ path_stubs = f"{ base_path } -stubs{ sepinit } .pyi"
512+ if fscache .isfile_case (path_stubs , dir_prefix ):
513+ if verify and not verify_module (fscache , id , path_stubs , dir_prefix ):
514+ near_misses .append ((path_stubs , dir_prefix ))
515+ else :
516+ return path_stubs
517+
509518 # Prefer package over module, i.e. baz/__init__.py* over baz.py*.
510519 for extension in PYTHON_EXTENSIONS :
511520 path = base_path + sepinit + extension
512- path_stubs = base_path + "-stubs" + sepinit + extension
513521 if fscache .isfile_case (path , dir_prefix ):
514522 has_init = True
515523 if verify and not verify_module (fscache , id , path , dir_prefix ):
516524 near_misses .append ((path , dir_prefix ))
517525 continue
518526 return path
519- elif fscache .isfile_case (path_stubs , dir_prefix ):
520- if verify and not verify_module (fscache , id , path_stubs , dir_prefix ):
521- near_misses .append ((path_stubs , dir_prefix ))
522- continue
523- return path_stubs
524527
525528 # In namespace mode, register a potential namespace package
526529 if self .options and self .options .namespace_packages :
0 commit comments