This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

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

Created on 2018-08-28 19:37 by Paul Pinterits, last changed 2022-04-11 14:59 by admin. This issue is now closed.

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 closed miss-islington, 2018-09-18 01:12
PR 9978 merged vstinner, 2018-10-19 23:03
PR 9979 merged vstinner, 2018-10-19 23:06
Messages (7)
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
msg328071 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-10-19 23:07
I wrote PR 9978 to backport the fix to Python 3.7.

Should the fix be backported to Python 3.6 as well?
msg328086 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2018-10-19 23:43
Change by STINNER Victor:

> pull_requests: +9319

Why does the above say 9319 when the PR is 9978?
msg328089 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2018-10-19 23:49
New changeset 0f2fc8bee0b435ee2934751264196db30d16ed8a by Ethan Furman (Victor Stinner) in branch '3.7':
bpo-34536: raise error for invalid _missing_ results (GH-9147) (GH-9978)
https://github.com/python/cpython/commit/0f2fc8bee0b435ee2934751264196db30d16ed8a
msg328090 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-10-19 23:54
> 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 :-)
msg328091 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2018-10-19 23:57
New changeset 4acf6c9d4be77b968fa498569d7a1545e5e77344 by Ethan Furman (Victor Stinner) in branch 'master':
bpo-34536: Cleanup test_enum imports (GH-9979)
https://github.com/python/cpython/commit/4acf6c9d4be77b968fa498569d7a1545e5e77344
History
Date User Action Args
2022-04-11 14:59:05adminsetgithub: 78717
2019-07-16 03:17:12ethan.furmansetkeywords: patch, patch, patch
status: open -> closed
resolution: fixed
stage: patch review -> resolved
2018-10-19 23:57:23ethan.furmansetmessages: + msg328091
2018-10-19 23:54:17vstinnersetkeywords: patch, patch, patch

messages: + msg328090
2018-10-19 23:49:33ethan.furmansetmessages: + msg328089
2018-10-19 23:43:09ethan.furmansetmessages: + msg328086
2018-10-19 23:07:51vstinnersetkeywords: patch, patch, patch
nosy: + vstinner
messages: + msg328071

2018-10-19 23:06:18vstinnersetpull_requests: + pull_request9320
2018-10-19 23:03:27vstinnersetpull_requests: + pull_request9319
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