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

Instantiating enum with invalid value results in ValueError twice #83909

Closed
jonasmalacofilho mannequin opened this issue Feb 23, 2020 · 6 comments
Closed

Instantiating enum with invalid value results in ValueError twice #83909

jonasmalacofilho mannequin opened this issue Feb 23, 2020 · 6 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

@jonasmalacofilho
Copy link
Mannequin

jonasmalacofilho mannequin commented Feb 23, 2020

BPO 39728
Nosy @warsaw, @ethanfurman, @epicfaace, @dorosch, @jonasmalacofilho
PRs
  • bpo-39728: enum with invalid value results in ValueError twice #18641
  • bpo-39728: Enum: fix duplicate ValueError #22277
  • [3.9] bpo-39728: Enum: fix duplicate ValueError (GH-22277) #22282
  • [3.8] bpo-39728: Enum: fix duplicate ValueError (GH-22277) #22283
  • 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-17.00:39:09.842>
    created_at = <Date 2020-02-23.09:07:04.775>
    labels = ['3.8', 'type-bug', 'library', '3.9', '3.10']
    title = 'Instantiating enum with invalid value results in ValueError twice'
    updated_at = <Date 2020-09-17.00:39:09.841>
    user = 'https://github.com/jonasmalacofilho'

    bugs.python.org fields:

    activity = <Date 2020-09-17.00:39:09.841>
    actor = 'ethan.furman'
    assignee = 'ethan.furman'
    closed = True
    closed_date = <Date 2020-09-17.00:39:09.842>
    closer = 'ethan.furman'
    components = ['Library (Lib)']
    creation = <Date 2020-02-23.09:07:04.775>
    creator = 'jonasmalaco'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 39728
    keywords = ['patch']
    message_count = 6.0
    messages = ['362496', '364209', '364210', '377004', '377033', '377034']
    nosy_count = 6.0
    nosy_names = ['barry', 'eli.bendersky', 'ethan.furman', 'epicfaace', 'dorosch', 'jonasmalaco']
    pr_nums = ['18641', '22277', '22282', '22283']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue39728'
    versions = ['Python 3.8', 'Python 3.9', 'Python 3.10']

    @jonasmalacofilho
    Copy link
    Mannequin Author

    jonasmalacofilho mannequin commented Feb 23, 2020

    Trying to instantiate an enum with an invalid value results in "During handling of the above exception, another exception occurred:".

    $ cat > test.py << EOF
    from enum import Enum
    class Color(Enum):
        RED = 1
        GREEN = 2
        BLUE = 3
    
    Color(0)
    EOF
    $ python --version
    Python 3.8.1
    
    
    $ python test.py
    ValueError: 0 is not a valid Color
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "test.py", line 8, in <module>
        Color(0)
      File "/usr/lib/python3.8/enum.py", line 304, in __call__
        return cls.__new__(cls, value)
      File "/usr/lib/python3.8/enum.py", line 595, in __new__
        raise exc
      File "/usr/lib/python3.8/enum.py", line 579, in __new__
        result = cls._missing_(value)
      File "/usr/lib/python3.8/enum.py", line 608, in _missing_
        raise ValueError("%r is not a valid %s" % (value, cls.__name__))
    ValueError: 0 is not a valid Color

    I think this might be related to 019f0a0 ("bpo-34536: raise error for invalid _missing_ results (GH-9147)"), but I haven't been able to confirm.

    @jonasmalacofilho jonasmalacofilho mannequin added 3.8 only security fixes 3.9 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Feb 23, 2020
    @ethanfurman ethanfurman self-assigned this Feb 23, 2020
    @epicfaace
    Copy link
    Mannequin

    epicfaace mannequin commented Mar 15, 2020

    I can't reproduce this on the latest python (3.9) from master. Can you?

    @epicfaace
    Copy link
    Mannequin

    epicfaace mannequin commented Mar 15, 2020

    Never mind, I was able to reproduce it.

    @ethanfurman ethanfurman added the 3.10 only security fixes label Sep 16, 2020
    @ethanfurman
    Copy link
    Member

    New changeset c95ad7a by Ethan Furman in branch 'master':
    bpo-39728: Enum: fix duplicate ValueError (GH-22277)
    c95ad7a

    @ethanfurman
    Copy link
    Member

    New changeset a9ba8ba by Ethan Furman in branch '3.9':
    [3.9] bpo-39728: Enum: fix duplicate ValueError (GH-22277) (GH-22282)
    a9ba8ba

    @ethanfurman
    Copy link
    Member

    New changeset 5efb1a7 by Ethan Furman in branch '3.8':
    [3.8] bpo-39728: Enum: fix duplicate ValueError (GH-22277) (GH-22283)
    5efb1a7

    @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

    1 participant