[docs] [issue37062] `AutoNumber` class in enum documentation: support *args in constructor

Reuben Thomas report at bugs.python.org
Mon May 27 02:03:00 EDT 2019

New submission from Reuben Thomas <rrt at sc3d.org>:

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.

assignee: docs at python
components: Documentation
files: foo.py
messages: 343607
nosy: docs at python, rrt
priority: normal
severity: normal
status: open
title: `AutoNumber` class in enum documentation: support *args in constructor
versions: Python 3.8
Added file: https://bugs.python.org/file48365/foo.py

Python tracker <report at bugs.python.org>

More information about the docs mailing list