Skip to content
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

Closed
rrt mannequin opened this issue May 27, 2019 · 8 comments
Closed

AutoNumber class in enum documentation: support *args in constructor #81243

rrt mannequin opened this issue May 27, 2019 · 8 comments
Assignees
Labels
3.10 only security fixes docs Documentation in the Doc dir

Comments

@rrt
Copy link
Mannequin

rrt mannequin commented May 27, 2019

BPO 37062
Nosy @ethanfurman, @ambv, @miss-islington
PRs
  • bpo-37062: Enum - add extended AutoNumber example #22349
  • [3.8] bpo-37062: Enum: add extended AutoNumber example (GH-22349) #22369
  • [3.9] bpo-37062: Enum: add extended AutoNumber example (GH-22349) #22370
  • Files
  • foo.py: Demo code
  • 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:

    assignee = 'https://github.com/ethanfurman'
    closed_at = <Date 2020-09-23.03:59:37.509>
    created_at = <Date 2019-05-27.06:03:00.596>
    labels = ['3.10', 'docs']
    title = '`AutoNumber` class in enum documentation: support *args in constructor'
    updated_at = <Date 2020-10-05.16:10:20.181>
    user = 'https://bugs.python.org/rrt'

    bugs.python.org fields:

    activity = <Date 2020-10-05.16:10:20.181>
    actor = 'lukasz.langa'
    assignee = 'ethan.furman'
    closed = True
    closed_date = <Date 2020-09-23.03:59:37.509>
    closer = 'ethan.furman'
    components = ['Documentation']
    creation = <Date 2019-05-27.06:03:00.596>
    creator = 'rrt'
    dependencies = []
    files = ['48365']
    hgrepos = []
    issue_num = 37062
    keywords = ['patch']
    message_count = 8.0
    messages = ['343607', '343608', '377291', '377292', '377355', '377356', '377357', '378056']
    nosy_count = 5.0
    nosy_names = ['docs@python', 'ethan.furman', 'lukasz.langa', 'rrt', 'miss-islington']
    pr_nums = ['22349', '22369', '22370']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue37062'
    versions = ['Python 3.10']

    @rrt
    Copy link
    Mannequin Author

    rrt mannequin commented May 27, 2019

    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.

    @rrt rrt mannequin assigned docspython May 27, 2019
    @rrt rrt mannequin added 3.8 only security fixes docs Documentation in the Doc dir labels May 27, 2019
    @rrt
    Copy link
    Mannequin Author

    rrt mannequin commented May 27, 2019

    Just to be clear, the proposed change to the documentation is simply to add ", *args" to the argument list of AutoNumber.__new__.

    @ethanfurman ethanfurman added 3.9 only security fixes and removed 3.8 only security fixes labels Mar 25, 2020
    @ethanfurman
    Copy link
    Member

    The only AutoNumber in the stdlib is as an example in the docs. Were you thinking of something else?

    @ethanfurman ethanfurman added 3.10 only security fixes and removed 3.9 only security fixes labels Sep 21, 2020
    @rrt
    Copy link
    Mannequin Author

    rrt mannequin commented Sep 21, 2020

    That's the one I was thinking of: the example in the docs.

    @ethanfurman
    Copy link
    Member

    New changeset 5acc1b5 by Miss Islington (bot) in branch '3.8':
    bpo-37062: Enum: add extended AutoNumber example (GH-22349) (GH-22369)
    5acc1b5

    @ethanfurman
    Copy link
    Member

    New changeset 64362c2 by Miss Islington (bot) in branch '3.9':
    bpo-37062: Enum: add extended AutoNumber example (GH-22349) (GH-22370)
    64362c2

    @ethanfurman
    Copy link
    Member

    Thank you, Reuben!

    @ambv
    Copy link
    Contributor

    ambv commented Oct 5, 2020

    New changeset e8165e7 by Łukasz Langa (Miss Islington (bot)) in branch '3.9':
    bpo-37062: Enum: add extended AutoNumber example (GH-22349) (GH-22370)
    e8165e7

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.10 only security fixes docs Documentation in the Doc dir
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants