A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2013-April/125660.html below:

[Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library

[Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library [Python-Dev] PEP 435 -- Adding an Enum type to the Python standard libraryEthan Furman ethan at stoneleaf.us
Sun Apr 28 04:29:55 CEST 2013
On 04/27/2013 07:12 PM, Greg Ewing wrote:
> Guido van Rossum wrote:
>> And __init__/__new__ probably shouldn't be
>> overridden.
>
> Why shouldn't __init__ be overridden? It's the obvious
> way to support Java-style enum-items-with-attributes.

Overriding __init__ is a PITA because __init__ is also called when you do

   Planet(3)  # get EARTH

and __init__ was expecting a gravitational constant and radius (or something like that).

A couple ways around that:

   1) have the metaclass store the args somewhere special (e.g. _args), have __init__ look like `def __init__(self, 
value=None)`, and have the body treat _args as if it were *args

   2) have a `_init` that the metaclass calls with the args instead of __init__

--
~Ethan~
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4