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: Unreachable condition: `if enum_class._member_type_ is object`
Type: Stage: resolved
Components: Tests Versions: Python 3.11
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: ethan.furman Nosy List: ethan.furman, sobolevn
Priority: normal Keywords: patch

Created on 2022-01-07 17:36 by sobolevn, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 30458 merged sobolevn, 2022-01-07 17:39
Messages (5)
msg409989 - (view) Author: Nikita Sobolev (sobolevn) * (Python triager) Date: 2022-01-07 17:36
This condition can never be `True`: https://github.com/python/cpython/blob/b127e70a8a682fe869c22ce04c379bd85a00db67/Lib/enum.py#L222-L223

Why? Because: 
1. It is executed only when `if not enum_class._use_args_:`: https://github.com/python/cpython/blob/b127e70a8a682fe869c22ce04c379bd85a00db67/Lib/enum.py#L215
2. But, `enum_class._use_args_` will always be `False` for cases when `enum_class._member_type_` is `object`
3. It is defined here: https://github.com/python/cpython/blob/b127e70a8a682fe869c22ce04c379bd85a00db67/Lib/enum.py#L937

So, I guess that removing this condition can simplify the `enum.py`.
Coverage shows that this part is not tested.

I will send a PR shortly.
msg410026 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2022-01-07 20:21
(2) is false.

>>> from enum import Enum
>>> 
>>> class MyEnum(Enum):
...     def __new__(cls, value):
...         member = object.__new__(cls)
...         return member
...     ONE = 1
... 

>>> MyEnum.ONE
MyEnum.ONE

>>> MyEnum._use_args_
True

>>> MyEnum._member_type_
<class 'object'>

If coverage shows a branch not being tested, design a test for it instead of removing the branch.
msg410033 - (view) Author: Nikita Sobolev (sobolevn) * (Python triager) Date: 2022-01-07 21:01
Yes, this is just a missing test. Not a wrong condition!
msg410040 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2022-01-07 21:44
New changeset 74d1663580d1914bd110c3ab7282451f5e2cd2b5 by Nikita Sobolev in branch 'main':
bpo-46296: [Enum] add a test for missing `value` recovery (GH-30458)
https://github.com/python/cpython/commit/74d1663580d1914bd110c3ab7282451f5e2cd2b5
msg410041 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2022-01-07 21:45
Thank you, Nikita!
History
Date User Action Args
2022-04-11 14:59:54adminsetgithub: 90454
2022-01-07 21:45:40ethan.furmansetstatus: open -> closed
resolution: fixed
messages: + msg410041

stage: test needed -> resolved
2022-01-07 21:44:27ethan.furmansetmessages: + msg410040
2022-01-07 21:01:40sobolevnsetmessages: + msg410033
components: + Tests, - Library (Lib)
2022-01-07 20:45:08ethan.furmansetmessages: - msg410029
2022-01-07 20:39:49ethan.furmansetmessages: + msg410029
2022-01-07 20:21:09ethan.furmansetnosy: + ethan.furman
messages: + msg410026

assignee: ethan.furman
stage: patch review -> test needed
2022-01-07 17:39:49sobolevnsetkeywords: + patch
stage: patch review
pull_requests: + pull_request28661
2022-01-07 17:36:29sobolevncreate