-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[ty] Teach ty the meaning of desperation (try ancestor pyproject.tomls as search-paths if module resolution fails)
#21745
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 ✅ |
|
The uses of
|
|
|
Actually I think it Just Works because the module lookup takes the importing file, so the fallback mode necessarily agrees with itself. |
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
invalid-argument-type |
1,749 | 0 | 0 |
unresolved-import |
0 | 644 | 17 |
invalid-parameter-default |
118 | 0 | 10 |
unresolved-reference |
0 | 72 | 0 |
possibly-missing-attribute |
49 | 1 | 14 |
non-subscriptable |
39 | 0 | 0 |
unresolved-attribute |
39 | 0 | 0 |
invalid-return-type |
24 | 0 | 0 |
no-matching-overload |
19 | 0 | 0 |
invalid-assignment |
15 | 0 | 0 |
unused-ignore-comment |
0 | 10 | 0 |
unknown-argument |
9 | 0 | 0 |
possibly-missing-import |
6 | 0 | 0 |
invalid-context-manager |
4 | 0 | 0 |
missing-argument |
3 | 0 | 0 |
unsupported-operator |
3 | 0 | 0 |
deprecated |
2 | 0 | 0 |
unsupported-base |
0 | 2 | 0 |
invalid-await |
1 | 0 | 0 |
invalid-type-form |
1 | 0 | 0 |
not-iterable |
1 | 0 | 0 |
| Total | 2,082 | 729 | 41 |
|
|
This is now ready for review. |
desperately_resolve_modulepyproject.tomls as search-paths if module resolution fails)
pyproject.tomls as search-paths if module resolution fails)ty the meaning of desperation (try ancestor pyproject.tomls as search-paths if module resolution fails)
|
Hard to be 100% confident because there's so Many changes but the ecosystem-analyzer results all look reasonable. |
CodSpeed Performance ReportMerging #21745 will not alter performanceComparing Summary
|
|
I think the increased memory usage on mypy-primer is just "we successfully resolved more imports and analyzed more code non-trivially" |
MichaReiser
left a comment
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.
This is great.
I think we have to figure out the cache invalidation story before landing this change.
Probably worth a separate PR but I wonder if that allows us to remove tests from our environment.root defaults
One caveat of this approach is that, I think, completions won't work for any of those modules. This might be surprising to users but is probably fine
carljm
left a comment
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.
Nice!
|
I'll probably need to ask Micha for help on the caching/clamping behaviour tomorrow (head full, clocking out for the day, maybe won't think it's so daunting when I wake up). |
|
Updates:
I just need to hammer out a query/caching |
|
Made |
|
I'm going to land this so we can kick the tires on this and unblock dogfooding, if the caching is wonky we can iterate on it. |
| ```py | ||
| x: str = "2" | ||
| ```cfg | ||
| home = /doo/doo/wop/cpython-3.13.2-macos-aarch64-none/bin |
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.
Ok this is maybe gonna seem unnecessary, but "wop" is an ethnic pejorative (at least in the US), so despite "doo wop" also being a vocal rhythm style, I think it would be safer at the next convenient opportunity to just go with something else here.
Summary
This makes an importing file a required argument to module resolution, and if the fast-path cached query fails to resolve the module, take the slow-path uncached (could be cached if we want)
desperately_resolve_modulewhich will walk up from the importing file until it finds apyproject.toml(arbitrary decision, we could try every ancestor directory), at which point it takes one last desperate attempt to use that directory as a search-path. We do not continue walking up once we've found apyproject.toml(arbitrary decision, we could keep going up).Running locally, this fixes every broken-for-workspace-reasons import in pyx's workspace!
Test Plan
The workspace tests see a huge improvement on most absolute imports.