Title: `AutoNumber` class in enum documentation: support *args in constructor
Type: Stage:
Components: Documentation Versions: Python 3.9
Status: open Resolution:
Dependencies: Superseder:
Assigned To: ethan.furman Nosy List: docs@python, ethan.furman, rrt
Priority: normal Keywords:

Created on 2019-05-27 06:03 by rrt, last changed 2020-03-25 21:59 by ethan.furman.

File name Uploaded Description Edit rrt, 2019-05-27 06:03 Demo code
Messages (2)
msg343607 - (view) Author: Reuben Thomas (rrt) Date: 2019-05-27 06:03
By changing one line of AutoNumber:

    def __new__(cls):


    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.
msg343608 - (view) Author: Reuben Thomas (rrt) Date: 2019-05-27 06:03
Just to be clear, the proposed change to the documentation is simply to add ", *args" to the argument list of AutoNumber.__new__.
Date User Action Args
2020-03-25 21:59:43ethan.furmansetversions: + Python 3.9, - Python 3.8
2020-03-25 21:59:24ethan.furmansetassignee: docs@python -> ethan.furman
2019-05-27 06:04:29xtreaksetnosy: + ethan.furman
2019-05-27 06:03:35rrtsetmessages: + msg343608
2019-05-27 06:03:00rrtcreate