[Python-Dev] [Python-checkins] peps: Pre-alpha draft for PEP 435 (enum). The name is not important at the moment, as (original) (raw)

Ethan Furman ethan at stoneleaf.us
Sat Feb 23 18:51:53 CET 2013


On 02/23/2013 09:15 AM, Eli Bendersky wrote:

Hmm, constants such as os.SEEK* which serve as inputs to stdlib rather than outputs can actually be a good candidate for enum without worrying about backwards compatibility.

The reason I make the input vs. output distinction, is that for stdlib code that returns values, the user may rely on their numeric values and if we switch to enum code will break. However, for os.SEEK* this is not the case. Thee can be aliases for enums: class SeekKind(Enum): SEEKSET = 0 SEEKCUR = 1 SEEKEND = 2 SEEKSET = SeekKind.SEEKSET ... lseek() can be changed to call 'int' on its input, and now os.SEEK* gain useful string representations when printed. Thoughts?

If that particular enum is int based, you don't have to

 a) make the distinction between input/output

 b) call 'int' on its input

and you /still/ get the useful string repr. ;)

-- Ethan



More information about the Python-Dev mailing list