On 25Mar2020 12:54, Ethan Furman <ethan@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 <cs@cskk.id.au>