ericvsmith / dataclasses

Apache License 2.0
587 stars 53 forks source link

Add support for per-field metadata #69

Closed ericvsmith closed 7 years ago

ericvsmith commented 7 years ago

See http://www.attrs.org/en/stable/extending.html#metadata for the equivalent functionality in attrs.

gvanrossum commented 7 years ago

This can just be an extra keyword for field(), right?

ericvsmith commented 7 years ago

Correct. attrs requires it to be a dict (or really any Mapping, I think) and then wraps it in a types.MappingProxyType to make it read-only. I haven't done enough research to understand why they do that, but I will. I assume we should just do the same to maximize compatibility.

This is the last item I want to complete before posting the updated PEP on python-dev.

ericvsmith commented 7 years ago

To clarify: I understand why you'd make it read-only if the metadata is a Mapping. What isn't clear to me is why only a Mapping is supported. At first blush I'd think that the metadata could be anything, and we shouldn't restrict it at all. But I'm sure attrs has a good reason for it.

ericvsmith commented 7 years ago

The answer is in https://github.com/python-attrs/attrs/issues/63#issuecomment-244053386 and the following discussion. A dict is used to force composability without resorting to multiple inheritance verbosity. It seems like a reasonable argument to me.

gvanrossum commented 7 years ago

+1.

ericvsmith commented 7 years ago

Closed via #71.