summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_unicode.py
diff options
context:
space:
mode:
authorEthan Furman <ethan@stoneleaf.us>2022-01-16 06:41:43 (GMT)
committerGitHub <noreply@github.com>2022-01-16 06:41:43 (GMT)
commitacf7403f9baea3ae1119fc6b4a3298522188bf96 (patch)
treefcffbb83c601353ac1fce9b35b0f2424c8ce9899 /Lib/test/test_unicode.py
parent37eab55ac9da6b6361f136a1da15bfcef12ed954 (diff)
downloadcpython-acf7403f9baea3ae1119fc6b4a3298522188bf96.zip
cpython-acf7403f9baea3ae1119fc6b4a3298522188bf96.tar.gz
cpython-acf7403f9baea3ae1119fc6b4a3298522188bf96.tar.bz2
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`
Diffstat (limited to 'Lib/test/test_unicode.py')
-rw-r--r--Lib/test/test_unicode.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py
index d5e2c52..8e4e648 100644
--- a/Lib/test/test_unicode.py
+++ b/Lib/test/test_unicode.py
@@ -1490,8 +1490,10 @@ class UnicodeTest(string_tests.CommonTest,
# issue18780
import enum
class Float(float, enum.Enum):
+ # a mixed-in type will use the name for %s etc.
PI = 3.1415926
class Int(enum.IntEnum):
+ # IntEnum uses the value and not the name for %s etc.
IDES = 15
class Str(enum.StrEnum):
# StrEnum uses the value and not the name for %s etc.
@@ -1508,8 +1510,10 @@ class UnicodeTest(string_tests.CommonTest,
# formatting jobs delegated from the string implementation:
self.assertEqual('...%(foo)s...' % {'foo':Str.ABC},
'...abc...')
+ self.assertEqual('...%(foo)r...' % {'foo':Int.IDES},
+ '...<Int.IDES: 15>...')
self.assertEqual('...%(foo)s...' % {'foo':Int.IDES},
- '...IDES...')
+ '...15...')
self.assertEqual('...%(foo)i...' % {'foo':Int.IDES},
'...15...')
self.assertEqual('...%(foo)d...' % {'foo':Int.IDES},