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._missing_ doesn't raise TypeError when a non-Enum object is a returned #78717

Closed
PaulPinterits mannequin opened this issue Aug 28, 2018 · 7 comments
Closed

Enum._missing_ doesn't raise TypeError when a non-Enum object is a returned #78717

PaulPinterits mannequin opened this issue Aug 28, 2018 · 7 comments
Assignees
Labels
3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@PaulPinterits
Copy link
Mannequin

PaulPinterits mannequin commented Aug 28, 2018

BPO 34536
Nosy @vstinner, @ethanfurman, @tirkarthi
PRs
  • bpo-34536: raise error for invalid _missing_ results #9147
  • bpo-34536: raise error for invalid _missing_ results #9147
  • bpo-34536: raise error for invalid _missing_ results #9147
  • [3.7] bpo-34536: raise error for invalid _missing_ results (GH-9147) #9381
  • [3.7] bpo-34536: raise error for invalid _missing_ results (GH-9147) #9978
  • bpo-34536: Cleanup test_enum imports #9979
  • 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 2019-07-16.03:17:12.404>
    created_at = <Date 2018-08-28.19:37:44.217>
    labels = ['3.7', 'type-bug', 'library']
    title = "Enum._missing_ doesn't raise TypeError when a non-Enum object is a returned"
    updated_at = <Date 2019-07-16.03:17:12.403>
    user = 'https://bugs.python.org/PaulPinterits'

    bugs.python.org fields:

    activity = <Date 2019-07-16.03:17:12.403>
    actor = 'ethan.furman'
    assignee = 'ethan.furman'
    closed = True
    closed_date = <Date 2019-07-16.03:17:12.404>
    closer = 'ethan.furman'
    components = ['Library (Lib)']
    creation = <Date 2018-08-28.19:37:44.217>
    creator = 'Paul Pinterits'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 34536
    keywords = ['patch', 'patch', 'patch']
    message_count = 7.0
    messages = ['324282', '325165', '328071', '328086', '328089', '328090', '328091']
    nosy_count = 4.0
    nosy_names = ['vstinner', 'ethan.furman', 'Paul Pinterits', 'xtreak']
    pr_nums = ['9147', '9147', '9147', '9381', '9978', '9979']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue34536'
    versions = ['Python 3.7']

    @PaulPinterits
    Copy link
    Mannequin Author

    PaulPinterits mannequin commented Aug 28, 2018

    In a conversation with Ethan Furman (the author of the enum module) I've been informed that Enum automatically checks whether the _missing_ method has returned an instance of the correct class, and raises a TypeError if not. (Link: https://stackoverflow.com/a/52064774/1222951)

    However, this simply does not happen.

    import enum
    
    class MyEnum(enum.Enum):
        FOO = "foo"
    
        @classmethod
        def _missing_(cls, value):
            return 5
    
    print(MyEnum('bar'))  # output: 5
    

    @PaulPinterits PaulPinterits mannequin added 3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Aug 28, 2018
    @ethanfurman ethanfurman self-assigned this Aug 31, 2018
    @ethanfurman
    Copy link
    Member

    New changeset 019f0a0 by Ethan Furman in branch 'master':
    bpo-34536: raise error for invalid _missing_ results (GH-9147)
    019f0a0

    @vstinner
    Copy link
    Member

    I wrote PR 9978 to backport the fix to Python 3.7.

    Should the fix be backported to Python 3.6 as well?

    @ethanfurman
    Copy link
    Member

    Change by STINNER Victor:

    pull_requests: +9319

    Why does the above say 9319 when the PR is 9978?

    @ethanfurman
    Copy link
    Member

    New changeset 0f2fc8b by Ethan Furman (Victor Stinner) in branch '3.7':
    bpo-34536: raise error for invalid _missing_ results (GH-9147) (GH-9978)
    0f2fc8b

    @vstinner
    Copy link
    Member

    Why does the above say 9319 when the PR is 9978?

    Roundup (the software running bugs.python.org) logs its own internal identifier for pull requests. Following https://bugs.python.org/pull_request9320 may help you to understand :-)

    @ethanfurman
    Copy link
    Member

    New changeset 4acf6c9 by Ethan Furman (Victor Stinner) in branch 'master':
    bpo-34536: Cleanup test_enum imports (GH-9979)
    4acf6c9

    @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.7 (EOL) end of life 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