[issue17961] Use enum names as values in enum.Enum convenience API
Antoine Pitrou added the comment: I agree with Nick here, there's no reason to auto-number constants in Python. This is not C :-) -- nosy: +pitrou ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17961 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17961] Use enum names as values in enum.Enum convenience API
Barry A. Warsaw added the comment: On May 13, 2013, at 10:10 AM, Antoine Pitrou wrote: I agree with Nick here, there's no reason to auto-number constants in Python. This is not C :-) Why should they be strings? Why not object()? Why is `x.value == str(x)` a useful invariant to hold? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17961 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17961] Use enum names as values in enum.Enum convenience API
Antoine Pitrou added the comment: I agree with Nick here, there's no reason to auto-number constants in Python. This is not C :-) Why should they be strings? Why not object()? Because strings are readable, I'd say. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17961 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17961] Use enum names as values in enum.Enum convenience API
Nick Coghlan added the comment: On 14 May 2013 00:06, Antoine Pitrou rep...@bugs.python.org wrote: Antoine Pitrou added the comment: I agree with Nick here, there's no reason to auto-number constants in Python. This is not C :-) Why should they be strings? Why not object()? Because strings are readable, I'd say. Yep. Since we no longer have a compelling reason for it to be anything else, it may as well be the human readable string. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17961 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17961] Use enum names as values in enum.Enum convenience API
Ethan Furman added the comment: So the repr will look like: Color.red: 'red' ? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17961 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17961] Use enum names as values in enum.Enum convenience API
Barry A. Warsaw added the comment: On May 13, 2013, at 02:06 PM, Antoine Pitrou wrote: Antoine Pitrou added the comment: I agree with Nick here, there's no reason to auto-number constants in Python. This is not C :-) Why should they be strings? Why not object()? Because strings are readable, I'd say. The repr would then be Color.red: Color.red Yuck. Also, you would have to allow for subclasses (e.g. IntEnum) to override auto-assignment. Clearly, you can't use strings for X = IntEnum('X', 'start middle end') -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17961 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17961] Use enum names as values in enum.Enum convenience API
Barry A. Warsaw added the comment: On May 13, 2013, at 02:24 PM, Nick Coghlan wrote: Yep. Since we no longer have a compelling reason for it to be anything else, it may as well be the human readable string. Again, why does it matter? That's the whole point of having a human readable str() and repr(). -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17961 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17961] Use enum names as values in enum.Enum convenience API
New submission from Nick Coghlan: I encountered an interesting suggestion [1] regarding the enum.Enum convenience API: use the member names as their values, rather than the current integers starting from one. Since we're now using definition order rather than value order for iteration, this suggestion makes a lot of sense to me. (again, posting this as something to consider after the accepted PEP is incorporated) [1] http://www.acooke.org/cute/Pythonssad0.html -- messages: 189013 nosy: ncoghlan priority: normal severity: normal stage: needs patch status: open title: Use enum names as values in enum.Enum convenience API type: enhancement ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17961 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17961] Use enum names as values in enum.Enum convenience API
Changes by Nick Coghlan ncogh...@gmail.com: -- dependencies: +Code, test, and doc review for PEP-0435 Enum versions: +Python 3.4 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17961 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17961] Use enum names as values in enum.Enum convenience API
Changes by Ethan Furman et...@stoneleaf.us: -- nosy: +ethan.furman ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17961 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17961] Use enum names as values in enum.Enum convenience API
Nick Coghlan added the comment: Specifically, my suggestion is that for auto-created enum members, the invariant asset x.value == str(x) should hold. In flufl.enum, using integers made sense because it relies on sorting of values to determine the iteration order. That's no longer a concern for the standard library version, as iteration has been changed to use definition order. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17961 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17961] Use enum names as values in enum.Enum convenience API
Ethan Furman added the comment: In flufl.enum integers also made since as that was the default back-end data type. Currently, the functional method allows a type declaration. The behavior there could be tweaked such that no specification meant no value (a truly valueless enum!), type=int means ints starting from 1, type=str meant str values of names, any other value and you better had made your own enum derived class to support it. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17961 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17961] Use enum names as values in enum.Enum convenience API
Changes by Barry A. Warsaw ba...@python.org: -- nosy: +barry ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17961 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17961] Use enum names as values in enum.Enum convenience API
Barry A. Warsaw added the comment: On May 12, 2013, at 10:57 AM, Nick Coghlan wrote: I encountered an interesting suggestion [1] regarding the enum.Enum convenience API: use the member names as their values, rather than the current integers starting from one. Since we're now using definition order rather than value order for iteration, this suggestion makes a lot of sense to me. Cute, but I want the functional API to be equivalent to the class syntax. Besides: X = Enum('X', ((name, name) for name in 'ant bee cat dog elk'.split())) is not so much typing. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17961 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17961] Use enum names as values in enum.Enum convenience API
Nick Coghlan added the comment: That gives the unqualified names, and I don't understand your other objection. The class syntax doesn't support implicit values at all. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17961 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17961] Use enum names as values in enum.Enum convenience API
Nick Coghlan added the comment: Accepting awkward implementation details when their rationale no longer applies doesn't make sense to me, no. The functional API originally used integers for good reasons. Over the course of the enum discussions, those reasons evaporated, but this wasn't noticed until after the PEP was accepted. However, the acceptance of the PEP is why I have proposed this as a post-incorporation change. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17961 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com