Open
Description
Recently I wrote a modification to the attrs.evolve
function that works like this:
@attrs.define
class Foo:
a: int
@attrs.define
class Bar(Foo):
b: str
foo = Foo(1)
bar = evolve_as(foo, Bar, b="2")
print(bar)
# Bar(a=1, b='2')
This was very useful for my particular use-case, which involved enriching a data object in a pipeline, so I thought that this might be a good fit for attrs.
My implementation did not require Bar
to be a subclass of Foo
, but I'm not sure about the design implications of that. Might be better to limit this to subclasses only.