Copy *self* and apply *changes*. This works similarly to `attrs.evolve` but that function does not work with :class:`attrs.Attribute`. It is mainly meant to be used for `transform-fields`. .. versionadded:: 20.3.0
(self, **changes)
| 2594 | |
| 2595 | # Don't use attrs.evolve since fields(Attribute) doesn't work |
| 2596 | def evolve(self, **changes): |
| 2597 | """ |
| 2598 | Copy *self* and apply *changes*. |
| 2599 | |
| 2600 | This works similarly to `attrs.evolve` but that function does not work |
| 2601 | with :class:`attrs.Attribute`. |
| 2602 | |
| 2603 | It is mainly meant to be used for `transform-fields`. |
| 2604 | |
| 2605 | .. versionadded:: 20.3.0 |
| 2606 | """ |
| 2607 | new = copy.copy(self) |
| 2608 | |
| 2609 | new._setattrs(changes.items()) |
| 2610 | |
| 2611 | if "alias" in changes and "alias_is_default" not in changes: |
| 2612 | # Explicit alias provided -- no longer the default. |
| 2613 | _OBJ_SETATTR.__get__(new)("alias_is_default", False) |
| 2614 | elif ( |
| 2615 | "name" in changes |
| 2616 | and "alias" not in changes |
| 2617 | # Don't auto-generate alias if the user picked picked the old one. |
| 2618 | and self.alias_is_default |
| 2619 | ): |
| 2620 | # Name changed, alias was auto-generated -- update it. |
| 2621 | _OBJ_SETATTR.__get__(new)( |
| 2622 | "alias", _default_init_alias_for(new.name) |
| 2623 | ) |
| 2624 | |
| 2625 | return new |
| 2626 | |
| 2627 | # Don't use _add_pickle since fields(Attribute) doesn't work |
| 2628 | def __getstate__(self): |