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.

Title: Enum: __str__ and friends sometimes erroneously replaced
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.10, Python 3.9, Python 3.8
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: ethan.furman Nosy List: barry, eli.bendersky, ethan.furman, miss-islington
Priority: normal Keywords: patch

Created on 2020-09-15 02:12 by ethan.furman, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 22250 merged ethan.furman, 2020-09-15 02:23
PR 22267 merged miss-islington, 2020-09-15 23:56
PR 22272 merged ethan.furman, 2020-09-16 05:53
Messages (4)
msg376924 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2020-09-15 02:12
If an Enum declares __str__, __repr__, __format__, or __reduce_ex__ to be object`s, then it will get replaced by the base Enum's corresponding method.  E.g.:

  class RegexFlag(IntFlag):

     IGNORECASE = I = 2

     def repr(self):
         return 're.%s' %

     __str__ = object.__str__

The intent of the above is have str(RegexFlag.I) == repr(RegexFlag.I) (with some quotes, of course), but currently RegexFlag.__str__ will be replaced with Flag.__str__.
msg376964 - (view) Author: miss-islington (miss-islington) Date: 2020-09-15 23:28
New changeset 22415ad62555d79bd583b4a7d6a96006624a8277 by Ethan Furman in branch 'master':
bpo-41789: honor object overrides in Enum classes (GH-22250)
msg376970 - (view) Author: miss-islington (miss-islington) Date: 2020-09-16 00:16
New changeset 929112ef81ccef20d3aef25c8a1142059ee941da by Miss Islington (bot) in branch '3.8':
bpo-41789: honor object overrides in Enum classes (GH-22250)
msg376986 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2020-09-16 10:58
New changeset a4677068dd61662f5a56b184d5e3aa07db65b88e by Ethan Furman in branch '3.9':
[3.9] bpo-41789: honor object overrides in Enum classes (GH-22250) (GH-22272)
Date User Action Args
2022-04-11 14:59:35adminsetgithub: 85955
2020-09-16 10:59:44ethan.furmansetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2020-09-16 10:58:53ethan.furmansetmessages: + msg376986
2020-09-16 05:53:37ethan.furmansetpull_requests: + pull_request21327
2020-09-16 00:16:46miss-islingtonsetmessages: + msg376970
2020-09-15 23:56:09miss-islingtonsetpull_requests: + pull_request21323
2020-09-15 23:28:34miss-islingtonsetnosy: + miss-islington
messages: + msg376964
2020-09-15 02:23:28ethan.furmansetkeywords: + patch
stage: needs patch -> patch review
pull_requests: + pull_request21306
2020-09-15 02:14:41ethan.furmanlinkissue41786 superseder
2020-09-15 02:12:45ethan.furmancreate