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

need StrEnum in enum.py #85982

Closed
ethanfurman opened this issue Sep 19, 2020 · 5 comments
Closed

need StrEnum in enum.py #85982

ethanfurman opened this issue Sep 19, 2020 · 5 comments
Assignees
Labels
3.10 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@ethanfurman
Copy link
Member

BPO 41816
Nosy @warsaw, @terryjreedy, @ethanfurman, @serhiy-storchaka
PRs
  • bpo-41816: add StrEnum #22337
  • bpo-41816: StrEnum.__str__ is str.__str__ #22362
  • 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-22.20:01:30.869>
    created_at = <Date 2020-09-19.19:20:58.192>
    labels = ['type-feature', 'library', '3.10']
    title = 'need StrEnum in enum.py'
    updated_at = <Date 2020-09-22.20:01:30.868>
    user = 'https://github.com/ethanfurman'

    bugs.python.org fields:

    activity = <Date 2020-09-22.20:01:30.868>
    actor = 'ethan.furman'
    assignee = 'ethan.furman'
    closed = True
    closed_date = <Date 2020-09-22.20:01:30.869>
    closer = 'ethan.furman'
    components = ['Library (Lib)']
    creation = <Date 2020-09-19.19:20:58.192>
    creator = 'ethan.furman'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 41816
    keywords = ['patch']
    message_count = 5.0
    messages = ['377186', '377294', '377321', '377347', '377348']
    nosy_count = 5.0
    nosy_names = ['barry', 'terry.reedy', 'eli.bendersky', 'ethan.furman', 'serhiy.storchaka']
    pr_nums = ['22337', '22362']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue41816'
    versions = ['Python 3.10']

    @ethanfurman
    Copy link
    Member Author

    Due to the nature of str, if an Enum tries to mixin the str type, all of it's members will be strings -- even if they didn't start out that way:

      class MyStrEnum(str, Enum):
         tuple = 'oops',
         okay = 'correct'
      >>> list(MyStrEnum)
      [<MyStrEnum.tuple: "('oops',)">, MyStrEnum.okay: 'correct'>]

    The StrEnum class will have a check to ensure that each value was already a string, or can be converted to a string via

      str(bytes, encoding, errors)

    @ethanfurman ethanfurman added the 3.10 only security fixes label Sep 19, 2020
    @ethanfurman ethanfurman self-assigned this Sep 19, 2020
    @ethanfurman ethanfurman added stdlib Python modules in the Lib dir type-feature A feature request or enhancement 3.10 only security fixes labels Sep 19, 2020
    @ethanfurman ethanfurman self-assigned this Sep 19, 2020
    @ethanfurman ethanfurman added stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Sep 19, 2020
    @ethanfurman
    Copy link
    Member Author

    New changeset 0063ff4 by Ethan Furman in branch 'master':
    bpo-41816: add StrEnum (GH-22337)
    0063ff4

    @ethanfurman
    Copy link
    Member Author

    From Serhiy Storchaka:
    ---------------------
    The only exception is StrEnum -- overriding __str__ of str
    subclass may be not safe. Some code will call str() implicitly, other
    will read the string content of the object directly, and they will be
    different.

    @ethanfurman ethanfurman reopened this Sep 22, 2020
    @ethanfurman ethanfurman reopened this Sep 22, 2020
    @ethanfurman
    Copy link
    Member Author

    New changeset d986d16 by Ethan Furman in branch 'master':
    bpo-41816: StrEnum.__str__ is str.__str__ (GH-22362)
    d986d16

    @ethanfurman
    Copy link
    Member Author

    Thank you for your help, Serhiy!

    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-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant