File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed
crates/ty_python_semantic/src/module_resolver Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -773,8 +773,17 @@ fn resolve_name_in_search_path(
773773
774774 // Last resort, check if a folder with the given name exists.
775775 // If so, then this is a namespace package.
776- // Exclude the standard library because it has conditional modules and we don't
777- // want to mistake them as namespace packages.
776+ // We need to skip this check for typeshed because the `resolve_file_module` can also return `None`
777+ // if the `__init__.py` exists but isn't available for the current Python version.
778+ // Let's assume that the `xml` module is only available on Python 3.11+ and we're resolving for Python 3.10:
779+ // * `resolve_file_module("xml/__init__.pyi")` returns `None` even though the file exists but the
780+ // module isn't available for the current Python version.
781+ // * The check here would now return `true` because the `xml` directory exists, resulting
782+ // in a false positive for a namespace package.
783+ //
784+ // Since typeshed doesn't use any namespace packages today (May 2025), simply skip this
785+ // check which also helps performance. If typeshed ever uses namespace packages, ensure that
786+ // this check also takes the `VERSIONS` file into consideration.
778787 if !search_path. is_standard_library ( ) && package_path. is_directory ( context) {
779788 if let Some ( path) = package_path. to_system_path ( ) {
780789 let system = context. db . system ( ) ;
You can’t perform that action at this time.
0 commit comments