mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 02:12:22 +00:00
![]()
Some checks are pending
CI / Determine changes (push) Waiting to run
CI / cargo fmt (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (release) (push) Waiting to run
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / Fuzz for new red-knot panics (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / check playground (push) Blocked by required conditions
CI / benchmarks (push) Blocked by required conditions
[Knot Playground] Release / publish (push) Waiting to run
## Summary Adds preliminary support for `NamedTuple`s, including: * No false positives when constructing a `NamedTuple` object * Correct signature for the synthesized `__new__` method, i.e. proper checking of constructor calls * A patched MRO (`NamedTuple` => `tuple`), mainly to make type inference of named attributes possible, but also to better reflect the runtime MRO. All of this works: ```py from typing import NamedTuple class Person(NamedTuple): id: int name: str age: int | None = None alice = Person(1, "Alice", 42) alice = Person(id=1, name="Alice", age=42) reveal_type(alice.id) # revealed: int reveal_type(alice.name) # revealed: str reveal_type(alice.age) # revealed: int | None # error: [missing-argument] Person(3) # error: [too-many-positional-arguments] Person(3, "Eve", 99, "extra") # error: [invalid-argument-type] Person(id="3", name="Eve") ``` Not included: * type inference for index-based access. * support for the functional `MyTuple = NamedTuple("MyTuple", […])` syntax ## Test Plan New Markdown tests ## Ecosystem analysis ``` Diagnostic Analysis Report ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━┓ ┃ Diagnostic ID ┃ Severity ┃ Removed ┃ Added ┃ Net Change ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━┩ │ lint:call-non-callable │ error │ 0 │ 3 │ +3 │ │ lint:call-possibly-unbound-method │ warning │ 0 │ 4 │ +4 │ │ lint:invalid-argument-type │ error │ 0 │ 72 │ +72 │ │ lint:invalid-context-manager │ error │ 0 │ 2 │ +2 │ │ lint:invalid-return-type │ error │ 0 │ 2 │ +2 │ │ lint:missing-argument │ error │ 0 │ 46 │ +46 │ │ lint:no-matching-overload │ error │ 19121 │ 0 │ -19121 │ │ lint:not-iterable │ error │ 0 │ 6 │ +6 │ │ lint:possibly-unbound-attribute │ warning │ 13 │ 32 │ +19 │ │ lint:redundant-cast │ warning │ 0 │ 1 │ +1 │ │ lint:unresolved-attribute │ error │ 0 │ 10 │ +10 │ │ lint:unsupported-operator │ error │ 3 │ 9 │ +6 │ │ lint:unused-ignore-comment │ warning │ 15 │ 4 │ -11 │ ├───────────────────────────────────┼──────────┼─────────┼───────┼────────────┤ │ TOTAL │ │ 19152 │ 191 │ -18961 │ └───────────────────────────────────┴──────────┴─────────┴───────┴────────────┘ Analysis complete. Found 13 unique diagnostic IDs. Total diagnostics removed: 19152 Total diagnostics added: 191 Net change: -18961 ``` I uploaded the ecosystem full diff (ignoring the 19k `no-matching-overload` diagnostics) [here](https://shark.fish/diff-namedtuple.html). * There are some new `missing-argument` false positives which come from the fact that named tuples are often created using unpacking as in `MyNamedTuple(*fields)`, which we do not understand yet. * There are some new `unresolved-attribute` false positives, because methods like `_replace` are not available. * Lots of the `invalid-argument-type` diagnostics look like true positives --------- Co-authored-by: Douglas Creager <dcreager@dcreager.net> |
||
---|---|---|
.. | ||
resources | ||
src | ||
tests | ||
build.rs | ||
Cargo.toml | ||
mdtest.py | ||
mdtest.py.lock |