| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
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.
There was a problem hiding this comment.
Maybe also add a section to what's new in 3.10?
Sorry, something went wrong.
There was a problem hiding this comment.
I thought blurb did that?
Sorry, something went wrong.
There was a problem hiding this comment.
No, blurb just updates Misc/NEWS, which is an endless list of things (though more focused than the commit log :-).
What's new in 3.10 is a separate doc written by human editor who curate the most important news and group it by affected area.
Sorry, something went wrong.
There was a problem hiding this comment.
Sorry, something went wrong.
There was a problem hiding this comment.
Also the versionchanged directive is needed in the module documentation.
Sorry, something went wrong.
grep -R "<[A-Za-z\.]*: [^>]*>" * Assuming no one comes up with a strong reason to not commit this PR, I will need to do some rewriting of enum.rst -- there's currently a good-sized section dealing with valueless Enums and updating the repr() to not show the value, etc. |
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.
There was a problem hiding this comment.
In this case I would prefer ~Perm.RWX or Perm(-8). But this may be a different issue.
Sorry, something went wrong.
There was a problem hiding this comment.
Negative values are no longer a thing -- they are converted to their positive equivalent.
Sorry, something went wrong.
There was a problem hiding this comment.
Perm(0) would look better.
Sorry, something went wrong.
There was a problem hiding this comment.
I went with 0x0 to match other non-Flag values, similarly to the way re.RegexFlag does it.
Sorry, something went wrong.
There was a problem hiding this comment.
And here I would prefer Perm.X|8.
Sorry, something went wrong.
There was a problem hiding this comment.
It is now Perm.X|0x8
Sorry, something went wrong.
There was a problem hiding this comment.
I think that it would more useful to use MyEnum.example.value or int(MyEnum.example) in the example.
Sorry, something went wrong.
There was a problem hiding this comment.
Yes, I added the .value here and in other places.
Sorry, something went wrong.
There was a problem hiding this comment.
You can use f-string with !r.
Sorry, something went wrong.
There was a problem hiding this comment.
Yes, but I'm not using f-strings anywhere else.
Sorry, something went wrong.
There was a problem hiding this comment.
At some point I'll switch all the %-interpolations to use f-strings.
Sorry, something went wrong.
There was a problem hiding this comment.
re?
Sorry, something went wrong.
There was a problem hiding this comment.
Oops. Looks like I need to add a test for that branch of code.
Sorry, something went wrong.
There was a problem hiding this comment.
What if add an attribute to the enum class which is set to the class name by default and can be set to the module name for enums whose members are exposed as globals?
return '%s.%s' % (self.__class__._namespacename, self.name)It will make easier customization of the repr.
Sorry, something went wrong.
There was a problem hiding this comment.
I think writing a custom __repr__ is not that difficult.
Sorry, something went wrong.
There was a problem hiding this comment.
For general code I would add a class method for converting value to string. Depending on the class octal or binary may be better than hexadecimal.
Sorry, something went wrong.
There was a problem hiding this comment.
Fair point.
Sorry, something went wrong.
There was a problem hiding this comment.
Also the versionchanged directive is needed in the module documentation.
Sorry, something went wrong.
There was a problem hiding this comment.
Now whichever of __str__ and __repr__ is called first will initialize _name_ for all time. Even if they do the same thing now, they might drift in the future. Should this initialization code be in a common function to make sure it's consistent? One option would be to override name() and do it there.
Sorry, something went wrong.
There was a problem hiding this comment.
The name is now initialized when the pseudo-member is created.
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
|
@gvanrossum RE: looking for Enum.__str__ output in docs: I manually checked the module documentation for each one that had enum constants. |
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
| Back | FazBrowse Home | New Git URL |
Enumerations created from Enum._convert_ will have their repr() changed to be
module.member_name
and their str() to be
member_name
The exception is StrEnum, whose str() will be
value
as in, the member's value.
https://bugs.python.org/issue40066