-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[ty] Fix namespace packages that behave like partial stubs #19994
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Diagnostic diff on typing conformance testsNo changes detected when running ty on typing conformance tests ✅ |
|
`/packages/foo-stubs/both.py`: | ||
`/packages/foo-stubs/both.pyi`: | ||
|
||
```py | ||
```pyi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(All these changes are a driveby fix that doesn't change the results but I realized was wrong and should be fixed)
|
||
## Namespace stub with missing module | ||
|
||
Namespace stubs are always partial. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have a reference that backs this claim? This is somewhat surprising to me and I remember that I struggled to find good documentation for what's supposed to happen in some of those non obvious cases
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://peps.python.org/pep-0561/#partial-stub-packages
Type checkers should treat namespace packages within stub-packages as incomplete since multiple distributions may populate them. Regular packages within namespace packages in stub-package distributions are considered complete unless a py.typed with partial\n is included.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be great to add this link to the test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thank you!
In implementing partial stubs I had observed that this continue in the namespace package code seemed erroneous since the same continue for partial stubs didn't work. Unfortunately I wasn't confident enough to push on that hunch. Fortunately I remembered that hunch to make this an easy fix.
The issue with the continue is that it bails out of the current search-path without testing any .py files. This breaks when for example
google
andgoogle-stubs
/types-google
are both in the same site-packages dir -- failing to find a module intypes-google
has us completely skip overgoogle
!Fixes astral-sh/ty#520