ruff/crates/red_knot_python_semantic/src
David Peter b32407b6f3
[red-knot] Dataclasses: synthesize `__init__` with proper signature (#17428)
## Summary

This changeset allows us to generate the signature of synthesized
`__init__` functions in dataclasses by analyzing the fields on the class
(and its superclasses). There are certain things that I have not yet
attempted to model in this PR, like `kw_only`,
[`dataclasses.KW_ONLY`](https://docs.python.org/3/library/dataclasses.html#dataclasses.KW_ONLY)
or functionality around
[`dataclasses.field`](https://docs.python.org/3/library/dataclasses.html#dataclasses.field).

ticket: https://github.com/astral-sh/ruff/issues/16651

## Ecosystem analysis

These two seem to depend on missing features in generics (see [relevant
code
here](9898ccbb78/tests/core/test_generics.py (L54))):

> ```diff
> + error[lint:unknown-argument]
/tmp/mypy_primer/projects/dacite/tests/core/test_generics.py:54:24:
Argument `x` does not match any known parameter
> + error[lint:unknown-argument]
/tmp/mypy_primer/projects/dacite/tests/core/test_generics.py:54:38:
Argument `y` does not match any known parameter
> ```



These two are true positives. See [relevant code
here](9898ccbb78/tests/core/test_config.py (L154-L161)).

> ```diff
> + error[lint:invalid-argument-type]
/tmp/mypy_primer/projects/dacite/tests/core/test_config.py:161:24:
Argument to this function is incorrect: Expected `int`, found
`Literal["test"]`
> + error[lint:invalid-argument-type]
/tmp/mypy_primer/projects/dacite/tests/core/test_config.py:172:24:
Argument to this function is incorrect: Expected `int | float`, found
`Literal["test"]`
> ```


This one depends on `**` unpacking of dictionaries, which we don't
support yet:

> ```diff
> + error[lint:missing-argument]
/tmp/mypy_primer/projects/mypy_primer/mypy_primer/globals.py:218:11: No
arguments provided for required parameters `new`, `old`, `repo`,
`type_checker`, `mypyc_compile_level`, `custom_typeshed_repo`,
`new_typeshed`, `old_typeshed`, `new_prepend_path`, `old_prepend_path`,
`additional_flags`, `project_selector`, `known_dependency_selector`,
`local_project`, `expected_success`, `project_date`, `shard_index`,
`num_shards`, `output`, `old_success`, `coverage`, `bisect`,
`bisect_output`, `validate_expected_success`,
`measure_project_runtimes`, `concurrency`, `base_dir`, `debug`, `clear`
> ```



## Test Plan

New Markdown tests.
2025-04-17 09:30:59 +02:00
..
module_resolver [red-knot] Initial support for `dataclass`es (#17353) 2025-04-15 10:39:21 +02:00
semantic_index [red-knot] Dataclasses: synthesize `__init__` with proper signature (#17428) 2025-04-17 09:30:59 +02:00
types [red-knot] Dataclasses: synthesize `__init__` with proper signature (#17428) 2025-04-17 09:30:59 +02:00
util [red-knot] Improve ergonomics for the `PySlice` trait (#13983) 2024-10-29 20:40:59 +00:00
ast_node_ref.rs Fixing various spelling errors (#16924) 2025-03-23 08:08:40 +00:00
db.rs [red-knot] Fix `python` setting in mdtests, and rewrite a `site-packages` test as an mdtest (#17222) 2025-04-06 18:24:32 +01:00
lib.rs [red-knot] Fix `python` setting in mdtests, and rewrite a `site-packages` test as an mdtest (#17222) 2025-04-06 18:24:32 +01:00
lint.rs Add knot.toml schema (#15735) 2025-02-07 10:59:40 +01:00
list.rs [red-knot] Don't use separate ID types for each alist (#16415) 2025-02-28 14:55:55 -05:00
module_name.rs [red-knot] Add initial support for `*` imports (#16923) 2025-03-24 17:15:58 +00:00
node_key.rs [red-knot] Use memory address as AST node key (#14317) 2024-11-13 14:35:54 +01:00
program.rs [red-knot] Change venv discovery (#17099) 2025-03-31 19:39:05 +02:00
python_platform.rs [red-knot] Default `python-platform` to current platform (#17183) 2025-04-09 12:05:18 +02:00
semantic_index.rs [red-knot] detect unreachable attribute assignments (#16852) 2025-04-14 09:23:20 +02:00
semantic_model.rs [red-knot] Goto type definition (#16901) 2025-04-02 12:12:48 +00:00
site_packages.rs [red-knot] Discover local venv folder in cli (#16917) 2025-03-28 17:59:49 +00:00
suppression.rs Use python.typing.org for typing documentation links (#17323) 2025-04-09 20:38:20 +02:00
symbol.rs [red-knot] detect unreachable attribute assignments (#16852) 2025-04-14 09:23:20 +02:00
types.rs [red-knot] Super-basic generic inference at call sites (#17301) 2025-04-16 15:07:36 -04:00
unpack.rs [red-knot] Factor out shared unpacking logic (#16595) 2025-03-28 23:52:51 +05:30