New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AutoNumber
class in enum documentation: support *args in constructor
#81243
Comments
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. |
Just to be clear, the proposed change to the documentation is simply to add ", *args" to the argument list of AutoNumber.__new__. |
The only |
That's the one I was thinking of: the example in the docs. |
Thank you, Reuben! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: