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

adjust enum.auto's behavior for StrEnum to return the enum name #86551

Closed
anntzer mannequin opened this issue Nov 17, 2020 · 5 comments
Closed

adjust enum.auto's behavior for StrEnum to return the enum name #86551

anntzer mannequin opened this issue Nov 17, 2020 · 5 comments
Assignees
Labels
3.10 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@anntzer
Copy link
Mannequin

anntzer mannequin commented Nov 17, 2020

BPO 42385
Nosy @warsaw, @ethanfurman
PRs
  • bpo-42385: StrEnum: fix _generate_next_value_ to return a str #23727
  • bpo-42385: [Enum] add _generate_next_value_ to StrEnum #23735
  • 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-12-10.20:21:34.606>
    created_at = <Date 2020-11-17.09:01:11.592>
    labels = ['type-bug', 'library', '3.10']
    title = "adjust enum.auto's behavior for StrEnum to return the enum name"
    updated_at = <Date 2020-12-10.21:28:39.762>
    user = 'https://github.com/anntzer'

    bugs.python.org fields:

    activity = <Date 2020-12-10.21:28:39.762>
    actor = 'Antony.Lee'
    assignee = 'ethan.furman'
    closed = True
    closed_date = <Date 2020-12-10.20:21:34.606>
    closer = 'ethan.furman'
    components = ['Library (Lib)']
    creation = <Date 2020-11-17.09:01:11.592>
    creator = 'Antony.Lee'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 42385
    keywords = ['patch']
    message_count = 5.0
    messages = ['381220', '381254', '382840', '382842', '382848']
    nosy_count = 3.0
    nosy_names = ['barry', 'eli.bendersky', 'ethan.furman']
    pr_nums = ['23727', '23735']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue42385'
    versions = ['Python 3.10']

    @anntzer
    Copy link
    Mannequin Author

    anntzer mannequin commented Nov 17, 2020

    Currently, enum.auto doesn't work with the new (Py3.10) StrEnum: class E(enum.StrEnum): a = enum.auto() results in TypeError: 1 is not a string.

    I would guess that the most reasonable behavior for auto() in a StrEnum would be to return the name itself, as implemented in the AutoName example at https://docs.python.org/3.10/library/enum.html#using-automatic-values. I believe that this may just be a matter of copying the corresponding _generate_next_value_ implementation into the definition of StrEnum?

    @anntzer anntzer mannequin added 3.10 only security fixes stdlib Python modules in the Lib dir labels Nov 17, 2020
    @ethanfurman
    Copy link
    Member

    A good idea.

    Since the Python opinion of enum members is that they be upper-cased, and every magic string constant I have seen is lower-case, StrEnum._generate_next_value_ should lower case the name. Users can substitute their own _gnv_ for different behavior.

    @ethanfurman ethanfurman self-assigned this Nov 17, 2020
    @ethanfurman ethanfurman added the type-bug An unexpected behavior, bug, or error label Nov 17, 2020
    @ethanfurman ethanfurman self-assigned this Nov 17, 2020
    @ethanfurman ethanfurman added the type-bug An unexpected behavior, bug, or error label Nov 17, 2020
    @ethanfurman ethanfurman changed the title Should enum.auto's behavior be adjusted for StrEnum to return the enum name? adjust enum.auto's behavior for StrEnum to return the enum name Dec 10, 2020
    @ethanfurman ethanfurman changed the title Should enum.auto's behavior be adjusted for StrEnum to return the enum name? adjust enum.auto's behavior for StrEnum to return the enum name Dec 10, 2020
    @ethanfurman
    Copy link
    Member

    New changeset efb13be by Ethan Furman in branch 'master':
    bpo-42385: [Enum] add _generate_next_value_ to StrEnum (GH-23735)
    efb13be

    @ethanfurman
    Copy link
    Member

    Thank you for finding that, Antony.

    @anntzer
    Copy link
    Mannequin Author

    anntzer mannequin commented Dec 10, 2020

    Thanks for implementing!

    @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 stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant