Message340537
> I think the best thing to do is write another decorator that adds this method. I've often thought that having a dataclasses_tools third-party module would be a good idea.
I'd be happy with a separate decorator in the standard library for adding these methods. Not so sure about a third-party module, the added value is probably not high enough to justify an extra dependency (assuming one is aware it exists in the first place).
> or assume the member type matches the type defined in the class.
This doesn't seem an unreasonable assumption to me. If I'm using a dataclass, I probably care enough about its member types to bother declaring them and I wouldn't mind if a particular method expects that the members actually match the types. This behaviour would be clearly documented.
Alternatively, if we go with a separate decorator, whether this assumption holds could be a parameter, something like:
def add_asdict(cls, name='asdict', strict=True) |
|
Date |
User |
Action |
Args |
2019-04-19 10:53:51 | gsakkis | set | recipients:
+ gsakkis, rhettinger, eric.smith, matrixise, xtreak |
2019-04-19 10:53:51 | gsakkis | set | messageid: <1555671231.43.0.440597437056.issue36662@roundup.psfhosted.org> |
2019-04-19 10:53:51 | gsakkis | link | issue36662 messages |
2019-04-19 10:53:51 | gsakkis | create | |
|