bpo-40066: Enum: modify repr() and str()#22392
Conversation
gvanrossum
left a comment
There was a problem hiding this comment.
Nice. How did you track down all the docs that need to be changed? (I note there aren't any doc changes do to the change in str().)
Sorry, something went wrong.
Assuming no one comes up with a strong reason to not commit this PR, I will need to do some rewriting of |
Sorry, something went wrong.
That doesn't look for occurrences of the str() though, which doesn't have any funky markup.
Are you planning to do that in the same PR? (I recommend it.) FWIW you're unlikely to get anyone to tell you not to commit this from GitHub reviewers or bpo readers. Was there a python-ideas thread? Maybe you want to ask Raymond (if he didn't already concur)? |
Sorry, something went wrong.
|
Who is this PR waiting for now? |
Sorry, something went wrong.
|
GvR wrote:
For me to make a few changes, and hopefully for Raymond to chime in. I'll update the bpo issue in case he didn't see my email. |
Sorry, something went wrong.
non-StrEnum `__str__` will print the member name StrEnum `__str__` will print the member value
if `enum.__str__` is either `Enum.__str__` or `global_enum_str` use the value's `__format__`
repr() = class.member_name str() = member_name
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
- repr() is now ``enum_class.member_name`` - str() is now ``member_name`` - add HOW-TO section for ``Enum`` - change main documentation to be an API reference
ea6308a to
7643863
Compare
March 26, 2021 04:30
|
@gvanrossum RE: looking for |
Sorry, something went wrong.
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
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
Enumerations created from
Enum._convert_will have theirrepr()changed to bemodule.member_nameand their
str()to bemember_nameThe exception is
StrEnum, whosestr()will bevalueas in, the member's value.
https://bugs.python.org/issue40066