Skip to content

[Sugar] Add PythonicPytree.replace() #1439

@georgematheos

Description

@georgematheos

In some of my code, I've been subclassing the following rather than PythonicPytree:

from dataclasses import replace

class UpdatablePytree(PythonicPytree):
    """A Pytree supporting self.replace(...) to functionally update fields."""

    def replace(self, **kwargs):
        return replace(self, **kwargs)

Any myobj: MyClass where MyClass is a sub-type of UpdateablePytree supports syntax like

mynewobj = myobj.replace(x=new_x_value, y=new_y_value)

to functionally update the values on the x and y field in myobj.

This issue proposes to add this implementation of .replace to PythonicPytree directly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions