On Sat, Sep 19, 2020 at 1:29 AM Ethan Furman <et...@stoneleaf.us> wrote:

> On 9/18/20 6:41 PM, Guido van Rossum 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
>  >  >>>
>  > ```
>
> I think that's too terse -- the first bit, whether class or module, repr
> or str, is very important -- especially if you have several enums using
> some of the same names for their members.
>

Hm, the more I think about it the more I like this proposal. :-)

When exploring in the REPL, my proposal *would* show the class name (but
not the module name -- one can cause obfuscation that way too, but it would
become unwieldy, and the custom seems to be top stop short of that).

But when printing casually, wouldn't it be nice if we could cause
end-user-friendly output to be produced by default? End users probably
don't care about the class name, but they would care about the color name.
E.g.

class Color(Enum):
    red = 0
    green = 1
    blue = 2

class Flowers(Enum):
    roses = 0
    violets = 1

def send_bouquet(flowers, color):
    print("I'm sending you a bouquet of", color, flowers)

Looking over the stdlib enums, these usually already have their "kind"
encoded in the name, e.g. AF_INET, SOCK_STREAM, SIGINT. And the re flags
are pretty unique as well (IGNORE, MULTILINE, DOTALL).

-- 
--Guido van Rossum (python.org/~guido)
*Pronouns: he/him **(why is my pronoun here?)*
<http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-change-the-world/>
_______________________________________________
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/GVSKPC5MZNXURP36MBA6R5UXKK2YMABB/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to