bpo-40066: Enum: modify `repr()` and `str()` by ethanfurman · Pull Request #22392 · python/cpython
create enum._stdlib_enum decorator for Enums created the normal way: it adjusts `__repr__` and `__str__` to be the same as if the Enum had been created using `_convert_` update various modules to use the new decorator
rename to `global_enum` and have `global_enum` update the module's namespace with the members remove `_stdlib_enum` where the enums were not being exported to the module's namespace
* rename global_int_repr --> global_enum_repr * adjust global_flag_repr to print hex number for out-of-range values * extract function when _generate_next_value_ is a static method
ethanfurman
changed the title
bpo-40066: Enum global
bpo-40066: Enum: modify repr() and str()repr() and str()
tacaswell added a commit to tacaswell/matplotlib that referenced this pull request
In Python 3.10 the repr and str representation of Enums changed from str: 'ClassName.NAME' -> 'NAME' repr: '<ClassName.NAME: value>' -> 'ClassName.NAME' which is more consistent with what str/repr should do, however this breaks boilerplate which needs to get the ClassName.NAME version in all versions of Python. Thus, we locally monkey patch our preferred str representation in here. bpo-40066 python/cpython#22392
tacaswell added a commit to tacaswell/matplotlib that referenced this pull request
In Python 3.10 the repr and str representation of Enums changed from str: 'ClassName.NAME' -> 'NAME' repr: '<ClassName.NAME: value>' -> 'ClassName.NAME' which is more consistent with what str/repr should do, however this breaks boilerplate which needs to get the ClassName.NAME version in all versions of Python. Thus, we locally monkey patch our preferred str representation in here. bpo-40066 python/cpython#22392
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters