Closed
Description
I was helping out in #python
and there was a question about setting an instance attribute back to default. I didn't find a way provided by attrs to do that . Did I miss it? If not, would that be of interest? I haven't thought much about how it should be provided but here's the implementation I wrote for them.
https://repl.it/@altendky/UnpleasantUnconsciousPi-1
def get_default(instance, attribute):
default = attr.fields_dict(type(instance))[attribute].default
if isinstance(default, attr.Factory):
if default.takes_self:
return default.factory(instance)
return default.factory()
return default
Metadata
Metadata
Assignees
Labels
No labels