Repository navigation
Enum: modify __repr__, __str__; update docs #84247
Copy link
Copy link
Closed
Labels
3.10 (EOL)end of lifeend of life3.11only security fixesonly security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement
Description
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee = 'https://github.com/ethanfurman'
closed_at = <Date 2022-01-23.00:28:03.406>
created_at = <Date 2020-03-25.19:48:58.219>
labels = ['type-feature', 'library', '3.10', '3.11']
title = 'Enum: modify __repr__, __str__; update docs'
updated_at = <Date 2022-01-23.00:28:03.406>
user = 'https://github.com/ethanfurman'bugs.python.org fields:
activity = <Date 2022-01-23.00:28:03.406>
actor = 'ethan.furman'
assignee = 'ethan.furman'
closed = True
closed_date = <Date 2022-01-23.00:28:03.406>
closer = 'ethan.furman'
components = ['Library (Lib)']
creation = <Date 2020-03-25.19:48:58.219>
creator = 'ethan.furman'
dependencies = []
files = []
hgrepos = []
issue_num = 40066
keywords = ['patch']
message_count = 25.0
messages = ['365019', '366190', '376900', '376913', '376915', '376918', '377495', '378019', '378239', '389869', '390895', '390956', '390976', '396790', '410676', '410711', '410758', '410773', '410775', '410796', '410797', '410801', '410802', '410803', '410805']
nosy_count = 16.0
nosy_names = ['barry', 'rhettinger', 'scoder', 'vstinner', 'christian.heimes', 'ezio.melotti', 'mrabarnett', 'eli.bendersky', 'ethan.furman', 'serhiy.storchaka', 'The Compiler', 'veky', 'mscuthbert', 'pablogsal', 'kulikjak', 'kumaraditya']
pr_nums = ['22392', '25116', '25118', '30582', '30632', '30637', '30643']
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue40066'
versions = ['Python 3.10', 'Python 3.11']Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
3.10 (EOL)end of lifeend of life3.11only security fixesonly security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement
Activity
ethanfurman commentedon Mar 25, 2020
Serhiy had the idea of having Enum._convert also modify the __str__ and __repr__ of newly created enumerations to display the module name instead of the enumeration name (https://bugs.python.org/msg325007):
--> socket.AF_UNIX
<AddressFamily.AF_UNIX: 1> ==> <socket.AF_UNIX: 1>
--> print(socket.AF_UNIX)
AddressFamily.AF_UNIX ==> socket.AF_UNIX
Thoughts?
vedgar commentedon Apr 11, 2020
Yes. And repr should be inverse of eval, but it's probably too late for that. :-/
ethanfurman commentedon Sep 14, 2020
Looks like the
remodule's flags have been updated separately in bpo-36548:For stdlib Enum conversions are we happy with that? Or should __str__ just print the numeric value?
vedgar commentedon Sep 14, 2020
If it's considered to be not too backwards-incompatible, I think it would be nice to have str different from repr. That way we can finetune what exactly we need. But we can already do almost exactly that with *int* instead of *str*, so it's not too compelling.
Much more important thing is the "repr as inverse of eval". Is there any way we can have that for our own enums (as a mixin or a decorator)?
It would be fantastic. :-)
ethanfurman commentedon Sep 14, 2020
"repr as inverse of eval" is nice to have, but it is not a requirement.
17 remaining items
kulikjak commentedon Jan 17, 2022
This also broke our Solaris build with the following error:
======================================================================
FAIL: testGetaddrinfo (test.test_socket.GeneralModuleTests)
----------------------------------------------------------------------
(test.test_socket.GeneralModuleTests fails with the same error).
The issue is almost certainly that on Solaris, SOCK_STREAM is defined as 2 rather than 1; the following simple program confirms that:
I'm just not sure whether to fix this with
assertRegexor a special branch for Solaris (though I am not sure whether everybody else uses 1 or it's more varied).vstinner commentedon Jan 17, 2022
New changeset 42a64c0 by Victor Stinner in branch 'main':
Revert "bpo-40066: [Enum] update str() and format() output (GH-30582)" (GH-30632)
42a64c0
vstinner commentedon Jan 17, 2022
Sorry, I had to revert the change since it broke the CI and it prevented to merge new PRs. Tell me if I can help to get this test fixed and to get this change merged again.
By the way, the PR 30582 was merged even if the Docs CI failed.
ethanfurman commentedon Jan 17, 2022
After merging in doc fix by kumaraditya303, I'll update tests so Solaris passes.
ethanfurman commentedon Jan 17, 2022
New changeset 83d544b by Kumar Aditya in branch 'main':
bpo-40066: [Enum] skip failing doc test (GH-30637)
83d544b
vstinner commentedon Jan 17, 2022
For this one, I suggest to replace the value with "..." doctest pattern.
ethanfurman commentedon Jan 17, 2022
vstinner wrote:
--------------
That bit of code is from the unittest suite, not the doctest suite.
I went with:
vstinner commentedon Jan 17, 2022
I created python/core-workflow#424 "Should we make the Docs CI mandatory on the Python main branch?".
ethanfurman commentedon Jan 17, 2022
New changeset 62a6594 by Ethan Furman in branch 'main':
bpo-40066: [Enum] fix tests (GH-30643)
62a6594
Fix Enum exports for Python 3.11
Update streams.py
Since Python 3.11 and [bpo-40066](python/cpython#84247), Enum.__str__…