python-attrs / python-attrs/attrs

evolve() and attr.ib(init=False, default="foo")

Open
#251 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug
Dominant language
Python
Stars
5.8k
Forks
480
Avg merge
2h 15m
Merged PRs (30d)
2

Description

As pointed out in https://github.com/ericvsmith/dataclasses/issues/42#issuecomment-330198369 attr.evolve() behaves rather weird if an attribute has

  1. init=False,
  2. a default/__attrs_post_init__, and
  3. attribute(s) are modified on the instance.

The new resulting object will always have the default value.

I think I can live with that limitation if we document it and it's probably a good reason to resolve #207 with sticking assoc around with a better name?


Giving it further thought, the raison d'être for evolve are immutable objects…so I think it's fine to just document this edge case and leave it be?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the attr.evolve documentation and the linked discussion about init=False attributes with defaults or attrs_post_init. Confirm the behavior described in the issue, then document this limitation and its interaction with modified instance attributes; done means the edge case is clearly explained to users.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.