[Python-Dev] PEP 557: Data Classes

Glenn Linderman v+python at g.nevcal.com
Mon Sep 18 16:50:30 EDT 2017


On 9/18/2017 11:37 AM, Ethan Furman wrote:
> On 09/11/2017 03:28 PM, Guido van Rossum wrote:
>
>> Oddly I don't like the enum (flag names get too long that way), but I 
>> do agree with everything else Barry said (it
>> should be a trivalue flag and please don't name it cmp).
>
> Hmmm, named constants are one of the motivating factors for having an 
> Enum type.  It's easy to keep the name a reasonable length, however: 
> export them into the module-level namespace.  re is an excellent 
> example; the existing flags were moved into a FlagEnum, and then (for 
> backwards compatibility) aliased back to the module level:
snip
> Likewise, if we had:
>
>     class Compare(enum.Enum):
>         NONE = 'each instance is an island'
>         EQUAL = 'instances can be equal to each other'
>         ORDERED = 'instances can be ordered and/or equal'
>     globals().update(Compare.__members__)
>
> then we can still use, for example, EQUAL, but get the more 
> informative repr and str when we need to.

I tend to like the Enum also. But maybe this is a case where there 
should be multiple different decorators:

@dataclass
@equality_dataclass
@ordered_datatclass
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20170918/b4e62f31/attachment.html>


More information about the Python-Dev mailing list