It might be desirable to allow user-supplied metadata dict as part of an Attribute for use later during introspection. Something like:
@attr.s
class A:
boring = attr.ib()
i_am_special = attr.ib(metadata = {'special': True})
def do_things(self):
for a in attr.fields(type(self)):
if a.metadata.get('special', False):
self.do_something(a.name)
else:
self.do_something_else(b.name)
(above example is assuming attrs populates metadata with an empty dict if not provided.
Perhaps this is encourages more metaprogramming than is healthy, but I had a need for this in my first use of attrs; the alternative was keeping an explicit list of special attribute names, which is not very DRY. Just looking for design/desirability feedback before working on a patch.
It might be desirable to allow user-supplied metadata dict as part of an Attribute for use later during introspection. Something like:
(above example is assuming attrs populates metadata with an empty dict if not provided.
Perhaps this is encourages more metaprogramming than is healthy, but I had a need for this in my first use of attrs; the alternative was keeping an explicit list of special attribute names, which is not very DRY. Just looking for design/desirability feedback before working on a patch.