On Sat, Sep 19, 2020 at 11:44 AM Guido van Rossum <[email protected]> wrote:
> Another brainstorm (or brainfart): maybe repr() should show the module/class 
> and the name, and str() should only show the name. We'd then get
> ```
> >>> # Mock-up!
> >>> print(str(re.i))
> IGNORE
> >>> print(repr(re.i))
> re.IGNORE
> >>>
> ```
> and similar for Color.RED:
> ```
> >>> # Another mock-up!
> >>> print(str(Color.RED))
> RED
> >>> print(repr(Color.RED))
> Color.RED
> >>>
> ```
>

+1. There's actually a bit of a weird edge case with IntFlag at the
moment, and this would bypass that, at least for the str().

>>> from enum import IntFlag, auto
>>> class UF(IntFlag):
...     CT_LOW_GRAVITY = auto()
...     FLYING = auto()
...
>>> UF.CT_LOW_GRAVITY | UF.FLYING
<UF.FLYING|CT_LOW_GRAVITY: 3>
>>> str(UF.CT_LOW_GRAVITY | UF.FLYING)
'UF.FLYING|CT_LOW_GRAVITY'

The "UF." prefix is put on the start of the combined group, which
means it's not actually evallable (for what it's worth), and it's that
bit inconsistent. I'm absolutely fine with removing the classname
altogether, so this would show as "FLYING|CT_LOW_GRAVITY".

ChrisA
_______________________________________________
Python-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/BEAZU4H3OS3PS45ZRZIVTPDGD7JSPGW7/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to