New submission from Reuben Thomas <r...@sc3d.org>:

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.

----------
assignee: docs@python
components: Documentation
files: foo.py
messages: 343607
nosy: docs@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 <rep...@bugs.python.org>
<https://bugs.python.org/issue37062>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to