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: Some RegexFlag cannot be printed in the repr
Type: Stage: resolved
Components: Versions: Python 3.11
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: ethan.furman, lukasz.langa, pablogsal
Priority: normal Keywords: patch

Created on 2021-08-16 22:03 by pablogsal, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 27789 merged pablogsal, 2021-08-16 22:17
Messages (8)
msg399688 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-08-16 22:03
When printing some instance of RegexFlag **in the REPL** it fails to print:

>>> import gc
# This prints a ton of objects, including the bad enum RegexFlag one
>>> gc.get_referrers(None) 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pablogsal/github/cpython/Lib/enum.py", line 1399, in global_flag_repr
    return "%x" % (module, cls_name, self._value_)
           ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
TypeError: %x format: an integer is required, not str
msg399690 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-08-16 22:06
(Deleted last message because it was incorrect)
msg399691 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-08-16 22:09
Simpler reproducer:

>>> import re
>>> re.RegexFlag(0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pablogsal/github/cpython/Lib/enum.py", line 1399, in global_flag_repr
    return "%x" % (module, cls_name, self._value_)
           ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
TypeError: %x format: an integer is required, not str
msg399692 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-08-16 22:14
This looks incorrect:

https://github.com/python/cpython/blob/1512bc21d60f098a9e9f37b44a2f6a9b49a3fd4f/Lib/enum.py#L1399
msg399827 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-08-18 09:38
Ethan, could you take a look at the PR? I added a few failing test methods since `repr` handling for global enum flags wasn't covered and looks unfinished. If you tell us what the expected return values should be, I'll finish the fix.
msg399863 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2021-08-18 18:56
`_name_` is only None if the entire enum value is outside any named member and `_boundary_` is `KEEP` -- so

    class Example(Flag, boundary=KEEP):
        first = auto()
        second = auto()
        third = auto()

    >>> Example(0)
    module.Example(0)

    >>> Example(8)
    module.Example(8)

No need to backport.
msg400271 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2021-08-25 14:24
New changeset 24da544014f78e6f1440d5ce5c2d14794a020340 by Pablo Galindo Salgado in branch 'main':
bpo-44929: [Enum] Fix global repr (GH-27789)
https://github.com/python/cpython/commit/24da544014f78e6f1440d5ce5c2d14794a020340
msg400408 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-08-27 10:09
repr(re.RegexFlag(0)) no longer crashes so we can close this.
History
Date User Action Args
2022-04-11 14:59:48adminsetgithub: 89092
2021-08-27 10:09:44lukasz.langasetstatus: open -> closed
resolution: fixed
messages: + msg400408

stage: patch review -> resolved
2021-08-25 14:24:37ethan.furmansetmessages: + msg400271
2021-08-18 18:56:33ethan.furmansetmessages: + msg399863
versions: - Python 3.10
2021-08-18 09:38:20lukasz.langasetnosy: + lukasz.langa
messages: + msg399827
2021-08-16 22:17:00pablogsalsetkeywords: + patch
stage: patch review
pull_requests: + pull_request26258
2021-08-16 22:14:07pablogsalsetmessages: + msg399692
2021-08-16 22:09:21pablogsalsetmessages: + msg399691
2021-08-16 22:06:35pablogsalsetmessages: + msg399690
2021-08-16 22:06:15pablogsalsetmessages: - msg399689
2021-08-16 22:05:48pablogsalsetmessages: + msg399689
2021-08-16 22:03:59pablogsalcreate