Skip to content

Conversation

Gankra
Copy link
Contributor

@Gankra Gankra commented Aug 15, 2025

@Gankra Gankra requested a review from carljm as a code owner August 15, 2025 17:40
@Gankra Gankra added the ty Multi-file analysis & type inference label Aug 15, 2025
@Gankra
Copy link
Contributor Author

Gankra commented Aug 15, 2025

(I need to write some proper tests but this fixes from authlib.integrations.requests_client import OAuth2Session)

Copy link
Contributor

github-actions bot commented Aug 15, 2025

Diagnostic diff on typing conformance tests

No changes detected when running ty on typing conformance tests ✅

@@ -796,7 +809,7 @@ fn resolve_name_in_search_path(
context: &ResolverContext,
name: &RelaxedModuleName,
search_path: &SearchPath,
) -> Result<(PackageKind, ResolvedName), PackageKind> {
) -> Result<(PackageKind, PyTyped, ResolvedName), (PackageKind, PyTyped)> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really gross and I considered factoring a proper type but literally only one function deals with this and immediately unpacks these so... eh?

Comment on lines +1050 to +1054
/// This implementation implies that once a `py.typed` is specified
/// all child packages inherit it, so they can never become Untyped.
/// However they can override whether that's Full or Partial by
/// redeclaring a `py.typed` file of their own.
fn inherit_parent(self, parent: Self) -> Self {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No idea if this is correct but i like it conceptually

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spec isn't totally clear here, it just says "This marker applies recursively: if a top-level package includes it, all its sub-packages MUST support type checking as well." It doesn't say anything about a sub-package going to partial where its parent was "full", or whatever. But I think this behavior is sensible.

Copy link
Contributor

github-actions bot commented Aug 15, 2025

mypy_primer results

No ecosystem changes detected ✅
No memory usage changes detected ✅

Copy link
Contributor

@carljm carljm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable to me! But yeah, should add some tests before we land it.

Comment on lines +1050 to +1054
/// This implementation implies that once a `py.typed` is specified
/// all child packages inherit it, so they can never become Untyped.
/// However they can override whether that's Full or Partial by
/// redeclaring a `py.typed` file of their own.
fn inherit_parent(self, parent: Self) -> Self {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spec isn't totally clear here, it just says "This marker applies recursively: if a top-level package includes it, all its sub-packages MUST support type checking as well." It doesn't say anything about a sub-package going to partial where its parent was "full", or whatever. But I think this behavior is sensible.

@Gankra
Copy link
Contributor Author

Gankra commented Aug 18, 2025

Added tests

Copy link
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. This looks good to me.

Can you coordinate with @BurntSushi to make sure partial is also considered for completions (#19883)?

It would be nice if some of those module resolver tests could be mdtests. I ported some module resolver tests but haven't had the time to migrate all, but it would be nice if we can avoid adding new once (unless it uses a mdtest feature that we aren't supporting yet)

/// Testing stub packages can be missing modules and we don't fallthrough
/// to the impl (when they don't declare py.typed partial)
#[test]
fn resolve_stub_module_missing_non_partial() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be an mdtest similar to

## Stubs only
The regular package isn't required for type checking.
```toml
[environment]
extra-paths = ["/packages"]
```
`/packages/foo-stubs/__init__.pyi`:
```pyi
class Foo:
name: str
age: int
```
`main.py`:
```py
from foo import Foo
reveal_type(Foo().name) # revealed: str
```

@BurntSushi
Copy link
Member

Can you coordinate with @BurntSushi to make sure partial is also considered for completions (#19883)?

I added astral-sh/ty#1042 to track this.

@Gankra
Copy link
Contributor Author

Gankra commented Aug 18, 2025

Oh sure I can make these mdtests.

@Gankra Gankra merged commit 0cb1abc into main Aug 18, 2025
37 checks passed
@Gankra Gankra deleted the gankra/stub-mod branch August 18, 2025 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ty Multi-file analysis & type inference
Projects
None yet
Development

Successfully merging this pull request may close these issues.

support py.typed with partial
4 participants