[ty] Improve resolution of absolute imports in tests#21817
Conversation
Diagnostic diff on typing conformance testsNo changes detected when running ty on typing conformance tests ✅ |
|
|
Hmm this is tricky with the tests we have written, I need to look into what pytest actually does/supports. |
|
Can't believe Carl convinced me randomly including tests with or without |
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
unresolved-import |
33 | 7,404 | 57 |
possibly-missing-attribute |
531 | 10 | 39 |
unresolved-reference |
0 | 535 | 0 |
invalid-argument-type |
509 | 4 | 5 |
unresolved-attribute |
283 | 3 | 0 |
unused-ignore-comment |
2 | 168 | 0 |
unknown-argument |
57 | 26 | 0 |
unsupported-operator |
72 | 0 | 0 |
missing-argument |
58 | 0 | 0 |
no-matching-overload |
58 | 0 | 0 |
invalid-assignment |
46 | 5 | 3 |
possibly-unresolved-reference |
0 | 50 | 0 |
invalid-method-override |
42 | 0 | 0 |
invalid-return-type |
5 | 10 | 1 |
non-subscriptable |
13 | 0 | 0 |
not-iterable |
7 | 0 | 4 |
invalid-exception-caught |
6 | 0 | 0 |
invalid-raise |
6 | 0 | 0 |
unsupported-base |
6 | 0 | 0 |
too-many-positional-arguments |
5 | 0 | 0 |
call-non-callable |
4 | 0 | 0 |
deprecated |
4 | 0 | 0 |
inconsistent-mro |
4 | 0 | 0 |
parameter-already-assigned |
3 | 0 | 0 |
conflicting-metaclass |
0 | 2 | 0 |
invalid-parameter-default |
1 | 0 | 0 |
| Total | 1,755 | 8,217 | 109 |
|
Notably having multiple desperate search-paths is problematic for resolving relative imports, with our two-phases |
|
One kind of hacky solution would be to refuse to consider the dir the file is in a desperate search-path in |
|
Tears of joy at how good these docs are omg https://docs.pytest.org/en/stable/explanation/pythonpath.html |
The same can be accomplished by reversing the priority of the desperate search-paths: try the farthest ancestor dir first, allowing us to resolve |
d29194a to
28e9c9a
Compare
|
woah oh god those results |
|
If not already done, we need to make sure that the option defaults and documentation reflect the newest change regarding the default root paths. |
|
I think the spack ecosystem results mostly suggest that it ought to have But I guess not doing that makes it a good test case for what happens when ty is used in a project with an unusual layout and no configuration... |
## Summary ./tests is now no longer an implicit root, per #21817
* origin/main: (22 commits) [ty] Allow gradual lower/upper bounds in a constraint set (#21957) [ty] disallow explicit specialization of type variables themselves (#21938) [ty] Improve diagnostics for unsupported binary operations and unsupported augmented assignments (#21947) [ty] update implicit root docs (#21955) [ty] Enable even more goto-definition on inlay hints (#21950) Document known lambda formatting deviations from Black (#21954) [ty] fix hover type on named expression target (#21952) Bump benchmark dependencies (#21951) Keep lambda parameters on one line and parenthesize the body if it expands (#21385) [ty] Improve resolution of absolute imports in tests (#21817) [ty] Support `__all__ += submodule.__all__` [ty] Change frequency of invalid `__all__` debug message [ty] Add `KnownUnion::to_type()` (#21948) [ty] Classify `cls` as class parameter (#21944) [ty] Stabilize rename (#21940) [ty] Ignore `__all__` for document and workspace symbol requests [ty] Attach db to background request handler task (#21941) [ty] Fix outdated version in publish diagnostics after `didChange` (#21943) [ty] avoid fixpoint unioning of types containing current-cycle Divergent (#21910) [ty] improve bad specialization results & error messages (#21840) ...
As of astral-sh/ruff#21817, ./tests are no longer implicitly included.
By teaching desperate resolution to try every possible ancestor that doesn't have an
__init__.py(i)when resolving absolute imports.testsfrom theenvironment.rootdefault ty#1782