]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
bpo-40066: [Enum] update str() and format() output (GH-30582)
authorEthan Furman <ethan@stoneleaf.us>
Sun, 16 Jan 2022 06:41:43 +0000 (22:41 -0800)
committerGitHub <noreply@github.com>
Sun, 16 Jan 2022 06:41:43 +0000 (22:41 -0800)
commitacf7403f9baea3ae1119fc6b4a3298522188bf96
treefcffbb83c601353ac1fce9b35b0f2424c8ce9899
parent37eab55ac9da6b6361f136a1da15bfcef12ed954
bpo-40066:  [Enum] update str() and format() output (GH-30582)

Undo rejected PEP-663 changes:

- restore `repr()` to its 3.10 status
- restore `str()` to its 3.10 status

New changes:

- `IntEnum` and `IntFlag` now leave `__str__` as the original `int.__str__` so that str() and format() return the same result
- zero-valued flags without a name have a slightly changed repr(), e.g. `repr(Color(0)) == '<Color: 0>'`
- update `dir()` for mixed-in types to return all the methods and attributes of the mixed-in type
- added `_numeric_repr_` to `Flag` to control display of unnamed values
- enums without doc strings have a more comprehensive doc string added
- `ReprEnum` added -- inheriting from this makes it so only `__repr__` is replaced, not `__str__` nor `__format__`; `IntEnum`, `IntFlag`, and `StrEnum` all inherit from `ReprEnum`
14 files changed:
Doc/howto/enum.rst
Doc/library/enum.rst
Doc/library/ssl.rst
Lib/enum.py
Lib/inspect.py
Lib/plistlib.py
Lib/re.py
Lib/ssl.py
Lib/test/test_enum.py
Lib/test/test_signal.py
Lib/test/test_socket.py
Lib/test/test_ssl.py
Lib/test/test_unicode.py
Misc/NEWS.d/next/Library/2022-01-13-11-41-24.bpo-40066.1QuVli.rst [new file with mode: 0644]