Issue 37062: AutoNumber
class in enum documentation: support *args in constructor (original) (raw)
Created on 2019-05-27 06:03 by rrt, last changed 2022-04-11 14:59 by admin. This issue is now closed.
Files | |||
---|---|---|---|
File name | Uploaded | Description | Edit |
foo.py | rrt,2019-05-27 06:03 | Demo code |
Pull Requests | |||
---|---|---|---|
URL | Status | Linked | Edit |
PR 22349 | merged | ethan.furman,2020-09-22 03:54 | |
PR 22369 | merged | miss-islington,2020-09-23 03:56 | |
PR 22370 | merged | miss-islington,2020-09-23 03:56 |
Messages (8) | ||
---|---|---|
msg343607 - (view) | Author: Reuben Thomas (rrt) | Date: 2019-05-27 06:03 |
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. | ||
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__. | ||
msg377291 - (view) | Author: Ethan Furman (ethan.furman) * ![]() |
Date: 2020-09-21 23:21 |
The only `AutoNumber` in the stdlib is as an example in the docs. Were you thinking of something else? | ||
msg377292 - (view) | Author: Reuben Thomas (rrt) | Date: 2020-09-21 23:25 |
That's the one I was thinking of: the example in the docs. | ||
msg377355 - (view) | Author: Ethan Furman (ethan.furman) * ![]() |
Date: 2020-09-23 03:57 |
New changeset 5acc1b5f0b62eef3258e4bc31eba3b9c659108c9 by Miss Islington (bot) in branch '3.8': bpo-37062: Enum: add extended AutoNumber example (GH-22349) (GH-22369) https://github.com/python/cpython/commit/5acc1b5f0b62eef3258e4bc31eba3b9c659108c9 | ||
msg377356 - (view) | Author: Ethan Furman (ethan.furman) * ![]() |
Date: 2020-09-23 03:58 |
New changeset 64362c2e435eddc5e84cea313d92bc0b96d227f7 by Miss Islington (bot) in branch '3.9': bpo-37062: Enum: add extended AutoNumber example (GH-22349) (GH-22370) https://github.com/python/cpython/commit/64362c2e435eddc5e84cea313d92bc0b96d227f7 | ||
msg377357 - (view) | Author: Ethan Furman (ethan.furman) * ![]() |
Date: 2020-09-23 03:59 |
Thank you, Reuben! | ||
msg378056 - (view) | Author: Łukasz Langa (lukasz.langa) * ![]() |
Date: 2020-10-05 16:10 |
New changeset e8165e79f57cb3ca60bf031c417f8fd20c99eaa2 by Łukasz Langa (Miss Islington (bot)) in branch '3.9': bpo-37062: Enum: add extended AutoNumber example (GH-22349) (GH-22370) https://github.com/python/cpython/commit/e8165e79f57cb3ca60bf031c417f8fd20c99eaa2 |
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-04-11 14:59:15 | admin | set | github: 81243 |
2020-10-05 16:10:20 | lukasz.langa | set | nosy: + lukasz.langamessages: + |
2020-09-23 03:59:37 | ethan.furman | set | status: open -> closedresolution: fixedmessages: + stage: patch review -> resolved |
2020-09-23 03:58:39 | ethan.furman | set | messages: + |
2020-09-23 03:57:56 | ethan.furman | set | messages: + |
2020-09-23 03:56:47 | miss-islington | set | pull_requests: + <pull%5Frequest21410> |
2020-09-23 03:56:30 | miss-islington | set | nosy: + miss-islingtonpull_requests: + <pull%5Frequest21409> |
2020-09-22 03:54:01 | ethan.furman | set | keywords: + patchstage: patch reviewpull_requests: + <pull%5Frequest21388> |
2020-09-21 23:25:21 | rrt | set | messages: + |
2020-09-21 23:21:03 | ethan.furman | set | messages: + versions: + Python 3.10, - Python 3.9 |
2020-03-25 21:59:43 | ethan.furman | set | versions: + Python 3.9, - Python 3.8 |
2020-03-25 21:59:24 | ethan.furman | set | assignee: docs@python -> ethan.furman |
2019-05-27 06:04:29 | xtreak | set | nosy: + ethan.furman |
2019-05-27 06:03:35 | rrt | set | messages: + |
2019-05-27 06:03:00 | rrt | create |