TL;DR  Changes may be coming to Enum str() and repr() -- your (informed) 
opinion requested.  :-)


Python-Dev thread [0], summary below:

As you may have noticed, Enums are starting to pop up all over the stdlib [1].

To facilitate transforming existing module constants to IntEnums there is
`IntEnum._convert_`.  In Issue36548 [2] Serhiy modified the __repr__ of 
RegexFlag:

  >>> import re
  >>> re.I
  re.IGNORECASE

I think for converted constants that that looks nice.  For anyone that wants the
actual value, it is of course available as the `.value` attribute:

  >>> re.I.value
  2

I'm looking for arguments relating to:

- should _convert_ make the default __repr__ be module_name.member_name?

- should _convert_ make the default __str__ be the same, or be the
  numeric value?

After discussions with Guido I made a (largely done) PR [3] which:

for stdlib global constants (such as RE)
   - repr() -> uses `module.member_name`
   - str() -> uses `member_name`

for stdlib non-global constants, and enums in general
   - repr() -> uses `class.member_name`
   - str() -> uses `member_name`

The questions I would most appreciate an answer to at this point:

- do you think the change has merit?
- why /shouldn't/ we make the change?

As a reminder, the underlying issue is trying to keep at least the stdlib Enum
representations the same for those that are replacing preexisting constants.

--
~Ethan~


[0] 
https://mail.python.org/archives/list/python-...@python.org/message/CHQW6THTDYNPPFWQ2KDDTUYSAJDCZFNP/

[1] I'm working on making their creation faster.  If anyone wanted to convert 
EnumMeta to C I would be grateful.

[2] https://bugs.python.org/issue36548

[3] https://github.com/python/cpython/pull/22392
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/QOET2GQ4KP22Q4WV6V5P4HZQF7TKPU4T/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to