diff --git a/crates/ty_python_semantic/resources/mdtest/import/partial_stub_packages.md b/crates/ty_python_semantic/resources/mdtest/import/partial_stub_packages.md index 3d01aa3ab4..b84faf4c85 100644 --- a/crates/ty_python_semantic/resources/mdtest/import/partial_stub_packages.md +++ b/crates/ty_python_semantic/resources/mdtest/import/partial_stub_packages.md @@ -54,9 +54,9 @@ partial ```pyi ``` -`/packages/foo-stubs/both.py`: +`/packages/foo-stubs/both.pyi`: -```py +```pyi class Both: both: str other: int @@ -107,9 +107,9 @@ extra-paths = ["/packages"] ```pyi ``` -`/packages/foo-stubs/both.py`: +`/packages/foo-stubs/both.pyi`: -```py +```pyi class Both: both: str other: int @@ -165,9 +165,9 @@ extra-paths = ["/packages"] ```pyi ``` -`/packages/foo-stubs/both.py`: +`/packages/foo-stubs/both.pyi`: -```py +```pyi class Both: both: str other: int @@ -230,9 +230,9 @@ extra-paths = ["/packages"] ```pyi ``` -`/packages/foo-stubs/bar/both.py`: +`/packages/foo-stubs/bar/both.pyi`: -```py +```pyi class Both: both: str other: int @@ -305,9 +305,9 @@ partial/n ```pyi ``` -`/packages/foo-stubs/bar/both.py`: +`/packages/foo-stubs/bar/both.pyi`: -```py +```pyi class Both: both: str other: int @@ -380,9 +380,9 @@ pArTiAl\n ```pyi ``` -`/packages/foo-stubs/bar/both.py`: +`/packages/foo-stubs/bar/both.pyi`: -```py +```pyi class Both: both: str other: int @@ -423,3 +423,48 @@ reveal_type(Both().both) # revealed: str reveal_type(Impl().impl) # revealed: Unknown reveal_type(Fake().fake) # revealed: Unknown ``` + +## Namespace stub with missing module + +Namespace stubs are always partial. + +This is a regression test for . + +```toml +[environment] +extra-paths = ["/packages"] +``` + +`/packages/parent-stubs/foo/both.pyi`: + +```pyi +class Both: + both: str + other: int +``` + +`/packages/parent/foo/both.py`: + +```py +class Both: ... +``` + +`/packages/parent/foo/impl.py`: + +```py +class Impl: + impl: str + other: int +``` + +`main.py`: + +```py +from parent.foo.both import Both +from parent.foo.impl import Impl +from parent.foo.fake import Fake # error: "Cannot resolve" + +reveal_type(Both().both) # revealed: str +reveal_type(Impl().impl) # revealed: str +reveal_type(Fake().fake) # revealed: Unknown +``` diff --git a/crates/ty_python_semantic/src/module_resolver/resolver.rs b/crates/ty_python_semantic/src/module_resolver/resolver.rs index 783bc4dfe3..d1974fac18 100644 --- a/crates/ty_python_semantic/src/module_resolver/resolver.rs +++ b/crates/ty_python_semantic/src/module_resolver/resolver.rs @@ -723,8 +723,7 @@ fn resolve_name(db: &dyn Db, name: &ModuleName, mode: ModuleResolveMode) -> Opti `{name}` but it is a namespace package, keep going." ); // stub exists, but the module doesn't. But this is a namespace package, - // keep searching the next search path for a stub package with the same name. - continue; + // fall through to looking for a non-stub package } } }