attr.evolve does not handle custom __init__s
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
Research direction
Reproduce the supplied custom-init example and compare attr.assoc with attr.evolve. Read the attr.assoc and attr.evolve documentation and entry points to determine whether this behavior is intentional; done means resolving the compatibility question and documenting or specifying the supported behavior.
Written by the indexing model from the issue text.
Description
attr.assoc appears to have been deprecated in #169 and is now scheduled for removal in favor of attr.evolve, but the latter appears to not be able to do all that the former can do (and the documentation seems to indicate that this gap is intentional).
Is there then a reason to deprecate the former, it seems like it should stay, or the functionality should go somewhere else? I can think of workarounds to change the way the below works, but want to make sure it's being broken intentionally -- as-is, it does work correctly with attr.assoc.
Sample code:
import attr
@attr.s(init=False)
class F(object):
args = attr.ib()
other = attr.ib()
def __init__(self, *args, **kwargs):
self.args = args
self.other = kwargs.pop("other")
if kwargs:
raise TypeError(kwargs)
def assoc_new_other(self, new):
return attr.assoc(self, other=new)
def evolve_new_other(self, new):
return attr.evolve(self, other=new)
f = F(1, 2, 3, other=12)
for which print f.assoc_new_other(new=13) succeeds (but warns will go away) and f.evolve_new_other(new=13) fails.
- Dominant language
- Python
- Stars
- 5.8k
- Forks
- 480
- Avg merge
- 2h 15m
- Merged PRs (30d)
- 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.
More from python-attrs/attrs
-
Difficulty 5/5 Over a week Newbie friendliness 20/100
python-attrs/attrs#1620 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 55/100
python-attrs/attrs#1596 · 2 comments · 1 reaction ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
python-attrs/attrs#1549 · 3 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 38/100
python-attrs/attrs#1543 · 2 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
python-attrs/attrs#1532 ·
All issues in python-attrs/attrs
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
zostera/django-bootstrap4#894 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
use-agent-os/agent-os#3276 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
zephyrproject-rtos/zephyr#119726 ·
-
area/auth bug comp/agent P3 platform/discord type/security
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
NousResearch/hermes-agent#117848 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
zilliztech/memsearch#759 ·