classification
Title: Enum._missing_ doesn't raise TypeError when a non-Enum object is a returned
Type: behavior Stage: patch review
Components: Library (Lib) Versions: Python 3.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: ethan.furman Nosy List: Paul Pinterits, ethan.furman, xtreak
Priority: normal Keywords: patch, patch, patch

Created on 2018-08-28 19:37 by Paul Pinterits, last changed 2018-09-18 01:12 by miss-islington.

Pull Requests
URL Status Linked Edit
PR 9147 merged ethan.furman, 2018-09-12 00:00
PR 9147 merged ethan.furman, 2018-09-12 00:00
PR 9147 merged ethan.furman, 2018-09-12 00:00
PR 9381 open miss-islington, 2018-09-18 01:12
Messages (2)
msg324282 - (view) Author: Paul Pinterits (Paul Pinterits) Date: 2018-08-28 19:37
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
```
msg325165 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2018-09-12 18:43
New changeset 019f0a0cb85ebc234356415f3638b9bd77528e55 by Ethan Furman in branch 'master':
bpo-34536: raise error for invalid _missing_ results (GH-9147)
https://github.com/python/cpython/commit/019f0a0cb85ebc234356415f3638b9bd77528e55
History
Date User Action Args
2018-09-18 01:12:20miss-islingtonsetpull_requests: + pull_request8805
2018-09-12 18:43:37ethan.furmansetmessages: + msg325165
2018-09-12 00:00:13ethan.furmansetkeywords: + patch
stage: patch review
pull_requests: + pull_request8638
2018-09-12 00:00:12ethan.furmansetkeywords: + patch
stage: (no value)
pull_requests: + pull_request8637
2018-09-12 00:00:08ethan.furmansetkeywords: + patch
stage: (no value)
pull_requests: + pull_request8636
2018-09-03 09:03:46xtreaksetnosy: + xtreak
2018-08-31 19:30:03ethan.furmansetassignee: ethan.furman

nosy: + ethan.furman
2018-08-28 19:37:44Paul Pinteritscreate