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

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):
>    SEEK_SET = 0
>    SEEK_CUR = 1
>    SEEK_END = 2
>
> SEEK_SET = SeekKind.SEEK_SET
> ...
>
> 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