mirror of
https://github.com/astral-sh/ruff.git
synced 2026-11-24 18:29:13 +08:00
## Summary
Passing a dataclass field with `init=False` to `copy.replace` raises a
`TypeError` at runtime. ty now excludes these fields from the signature
of the synthesized `__replace__` method.
```py
from copy import replace
from dataclasses import dataclass, field
@dataclass
class User:
name: str
id: int = field(init=False, default=0)
user = User(name="Alice")
replace(user, name="Bob") # ok
replace(user, id=42) # ty now reports an unknown argument here
```
This also applies to attrs classes, Pydantic dataclasses and other
classes that use `dataclass_transform`.