Author rrt
Recipients docs@python, rrt
Date 2019-05-27.06:03:00
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1558936980.63.0.0585299344314.issue37062@roundup.psfhosted.org>
In-reply-to
Content
By changing one line of AutoNumber:

    def __new__(cls):

to

    def __new__(cls, *args):

Enums derived from AutoNumber can now support constructors that take named arguments; for example:

class Color(AutoNumber):
    def __init__(self, pantone=None):
        self.pantone = pantone or 'unknown'

class Swatch(Color):
    AUBURN = ('3497')
    SEA_GREEN = ('1246')
    BLEACHED_CORAL = () # New color, no Pantone code yet!

Without the change, one gets the error:

TypeError: __new__() takes 1 positional argument but 2 were given

I attach runnable demonstration code.
History
Date User Action Args
2019-05-27 06:03:00rrtsetrecipients: + rrt, docs@python
2019-05-27 06:03:00rrtsetmessageid: <1558936980.63.0.0585299344314.issue37062@roundup.psfhosted.org>
2019-05-27 06:03:00rrtlinkissue37062 messages
2019-05-27 06:03:00rrtcreate