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

Enum: __str__ and friends sometimes erroneously replaced #85955

Closed
ethanfurman opened this issue Sep 15, 2020 · 4 comments
Closed

Enum: __str__ and friends sometimes erroneously replaced #85955

ethanfurman opened this issue Sep 15, 2020 · 4 comments
Assignees
Labels
3.8 only security fixes 3.9 only security fixes 3.10 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@ethanfurman
Copy link
Member

BPO 41789
Nosy @warsaw, @ethanfurman, @miss-islington
PRs
  • bpo-41789: honor object overrides in Enum classes #22250
  • [3.8] bpo-41789: honor object overrides in Enum classes (GH-22250) #22267
  • [3.9] bpo-41789: honor object overrides in Enum classes (GH-22250) #22272
  • 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-16.10:59:44.801>
    created_at = <Date 2020-09-15.02:12:45.744>
    labels = ['3.8', 'type-bug', 'library', '3.9', '3.10']
    title = 'Enum: __str__ and friends sometimes erroneously replaced'
    updated_at = <Date 2020-09-16.10:59:44.800>
    user = 'https://github.com/ethanfurman'

    bugs.python.org fields:

    activity = <Date 2020-09-16.10:59:44.800>
    actor = 'ethan.furman'
    assignee = 'ethan.furman'
    closed = True
    closed_date = <Date 2020-09-16.10:59:44.801>
    closer = 'ethan.furman'
    components = ['Library (Lib)']
    creation = <Date 2020-09-15.02:12:45.744>
    creator = 'ethan.furman'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 41789
    keywords = ['patch']
    message_count = 4.0
    messages = ['376924', '376964', '376970', '376986']
    nosy_count = 4.0
    nosy_names = ['barry', 'eli.bendersky', 'ethan.furman', 'miss-islington']
    pr_nums = ['22250', '22267', '22272']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue41789'
    versions = ['Python 3.8', 'Python 3.9', 'Python 3.10']

    @ethanfurman
    Copy link
    Member Author

    If an Enum declares __str__, __repr__, __format__, or __reduce_ex__ to be object`s, then it will get replaced by the base Enum's corresponding method. E.g.:

      class RegexFlag(IntFlag):
    
         IGNORECASE = I = 2
    
         def repr(self):
             return 're.%s' % self.name
    
         __str__ = object.__str__

    The intent of the above is have str(RegexFlag.I) == repr(RegexFlag.I) (with some quotes, of course), but currently RegexFlag.__str__ will be replaced with Flag.__str__.

    @ethanfurman ethanfurman added 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes labels Sep 15, 2020
    @ethanfurman ethanfurman self-assigned this Sep 15, 2020
    @ethanfurman ethanfurman added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes labels Sep 15, 2020
    @ethanfurman ethanfurman self-assigned this Sep 15, 2020
    @ethanfurman ethanfurman added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Sep 15, 2020
    @miss-islington
    Copy link
    Contributor

    New changeset 22415ad by Ethan Furman in branch 'master':
    bpo-41789: honor object overrides in Enum classes (GH-22250)
    22415ad

    @miss-islington
    Copy link
    Contributor

    New changeset 929112e by Miss Islington (bot) in branch '3.8':
    bpo-41789: honor object overrides in Enum classes (GH-22250)
    929112e

    @ethanfurman
    Copy link
    Member Author

    New changeset a467706 by Ethan Furman in branch '3.9':
    [3.9] bpo-41789: honor object overrides in Enum classes (GH-22250) (GH-22272)
    a467706

    @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.8 only security fixes 3.9 only security fixes 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

    2 participants