19.09.20 00:44, Ethan Furman пише: > I'm looking for arguments relating to: > > - should _convert_ make the default __repr__ be module_name.member_name?
In most cases enums with _convert_ are used to replace old module globals. They are accessible as module_name.member_name and always used as module_name.member_name in user code. Also module_name.member_name is usually shorter than module_name.class_name.member_name or <class_name.member_name: value>. And the main advantage to me is using repr in compound objects: "foo.Command(action=foo.READ, kind=foo.FILE)" can be copied just from the debug output to the test code in contrary to "foo.Command(action=<Action.READ: 128>, kind=<ObjectKind.FILE: <object object at 0x7fcedc383f10>>)" which needs a lot of editing (and I often need to copy a list or a dict of such objects). I always override the default __repr__ in production code. > - should _convert_ make the default __str__ be the same, or be the > numeric value? I do not think that exposing the numeric value in __str__ would be useful. Numeric values are often arbitrary, this is why we use names at first place. The only exception is StrEnum -- overriding __str__ of str subclass may be not safe. Some code will call str() implicitly, other will read the string content of the object directly, and they will be different. I would consider returning just the member name from __str__. It have its pros and contras, so in the face of ambiguity it is better to restore the default implementation: __str__ = object.__str__. _______________________________________________ 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/WZGSSQ5B6TAUSY5C2PPC7QTHRWBST6GJ/ Code of Conduct: http://python.org/psf/codeofconduct/