On 25Mar2020 12:54, Ethan Furman <et...@stoneleaf.us> wrote:
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?
I'm uncomfortable. The socket module is something of a special case
because its enums come from the C library constants, which therefore
have nice global names like "AF_UNIX" because C is one big namespace;
you can infer that they are address family constants from their prefix.
I think a more "Python normal" module might have multiple enum classes,
maybe with overlapping names. Invented but plausible example:
class ANSIColourNames(enum):
NORMAL = 0
REVERSE = 7
UNDERLINE = 4
BOLD = 1
BLACK = 30
RED = 31
...
and another:
class SpecialNonANSITerminalCOlours(enum):
NORMAL = 0
REVERSE = 15
RED = 3
...
i.e. different classes with the same purpose specific enum names inside.
If I only got a module name back from __str__ I'd be underwhelmed.
I think I'd at least like the behaviour switchable in some way.
Cheers,
Cameron Simpson <c...@cskk.id.au>
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at
https://mail.python.org/archives/list/python-dev@python.org/message/DXA7DNOSSH7F4UTA2Q2NNT6QGQMVSKDI/
Code of Conduct: http://python.org/psf/codeofconduct/