mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 18:28:24 +00:00
![]() ## Summary Fix the lookup of `submodule`s in cases where the `parent` module has a self-referential import like `from parent import submodule`. This allows us to infer proper types for many symbols where we previously inferred `Never`. This leads to many new false (and true) positives across the ecosystem because the fact that we previously inferred `Never` shadowed a lot of problems. For example, we inferred `Never` for `os.path`, which is why we now see a lot of new diagnostics related to `os.path.abspath` and similar. ```py import os reveal_type(os.path) # previously: Never, now: <module 'os.path'> ``` closes https://github.com/astral-sh/ty/issues/261 closes https://github.com/astral-sh/ty/issues/307 ## Ecosystem analysis ``` ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━┓ ┃ Diagnostic ID ┃ Severity ┃ Removed ┃ Added ┃ Net Change ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━┩ │ call-non-callable │ error │ 1 │ 5 │ +4 │ │ call-possibly-unbound-method │ warning │ 6 │ 26 │ +20 │ │ invalid-argument-type │ error │ 26 │ 94 │ +68 │ │ invalid-assignment │ error │ 18 │ 46 │ +28 │ │ invalid-context-manager │ error │ 9 │ 4 │ -5 │ │ invalid-raise │ error │ 1 │ 1 │ 0 │ │ invalid-return-type │ error │ 3 │ 20 │ +17 │ │ invalid-super-argument │ error │ 4 │ 0 │ -4 │ │ invalid-type-form │ error │ 573 │ 0 │ -573 │ │ missing-argument │ error │ 2 │ 10 │ +8 │ │ no-matching-overload │ error │ 0 │ 715 │ +715 │ │ non-subscriptable │ error │ 0 │ 35 │ +35 │ │ not-iterable │ error │ 6 │ 7 │ +1 │ │ possibly-unbound-attribute │ warning │ 14 │ 31 │ +17 │ │ possibly-unbound-import │ warning │ 13 │ 0 │ -13 │ │ possibly-unresolved-reference │ warning │ 0 │ 8 │ +8 │ │ redundant-cast │ warning │ 1 │ 0 │ -1 │ │ too-many-positional-arguments │ error │ 2 │ 0 │ -2 │ │ unknown-argument │ error │ 2 │ 0 │ -2 │ │ unresolved-attribute │ error │ 583 │ 304 │ -279 │ │ unresolved-import │ error │ 0 │ 96 │ +96 │ │ unsupported-operator │ error │ 0 │ 17 │ +17 │ │ unused-ignore-comment │ warning │ 29 │ 2 │ -27 │ ├───────────────────────────────┼──────────┼─────────┼───────┼────────────┤ │ TOTAL │ │ 1293 │ 1421 │ +128 │ └───────────────────────────────┴──────────┴─────────┴───────┴────────────┘ Analysis complete. Found 23 unique diagnostic IDs. Total diagnostics removed: 1293 Total diagnostics added: 1421 Net change: +128 ``` * We see a lot of new errors (`no-matching-overload`) related to `os.path.dirname` and other `os.path` operations because we infer `str | None` for `__file__`, but many projects use something like `os.path.dirname(__file__)`. * We also see many new `unresolved-attribute` errors related to the fact that we now infer proper module types for some imports (e.g. `import kornia.augmentation as K`), but we don't allow implicit imports (e.g. accessing `K.auto.operations` without also importing `K.auto`). See https://github.com/astral-sh/ty/issues/133. * Many false positive `invalid-type-form` are removed because we now infer the correct type for some type expression instead of `Never`, which is not valid in a type annotation/expression context. ## Test Plan Added new Markdown tests |
||
---|---|---|
.. | ||
mdtest | ||
primer | ||
README.md |
Markdown files within the mdtest/
subdirectory are tests of type inference and type checking;
executed by the tests/mdtest.rs
integration test.
See crates/ty_test/README.md
for documentation of this test format.