attrs `copy.replace()` support
Open
Nobody has claimed this yet.
feature
topic-attrs
topic-plugins
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
attrs 24.3.0 added support for __replace__ in https://github.com/python-attrs/attrs/pull/1383. mypy doesn't like it.
To Reproduce
import copy
from attrs import define
@define
class Foo:
one: int
foo = Foo(1)
bar = copy.replace(foo, one=2)
Actual Behavior
a.py:12: error: Value of type variable "_SR" of "replace" cannot be "Foo" [type-var]
Your Environment
- Mypy version used: 1.13.0
- Mypy command-line flags:
mypy . - Mypy configuration options from
mypy.ini(and other config files): N/A - Python version used: 3.13.1
Package Version
----------------- -------
attrs 24.3.0
mypy 1.13.0
mypy-extensions 1.0.0
typing-extensions 4.12.2
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the reported Python 3.13 reproduction with mypy 1.13.0, then trace how the type checker models copy.replace and the attrs-generated replace. Check the existing tests around these typing or standard-library interactions. Done means the example type-checks without the reported type-var error while existing tests remain passing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100