PEP 354: Enumerations in Python

Roy Smith roy at panix.com
Wed Mar 1 09:49:52 EST 2006


Tim Chase  <python.list at tim.thechases.com> wrote:
>>> Do you anticipate having parameters like socket.AF_INET
>>> that are currently integers, become enumeration members
>>> in future releases?
>> 
>> Since these are derived from values defined as integers
>> in C, it's probably better to leave them that way. There
>> may be code that relies on them being integers or having
>> those integer values.
>
>I'd say that "because something is done in C, it's the best 
>way to do it in Python" is a bad line of reasoning :)  If I 
>wanted C, I'd use C.

The problem is that the C language binding in this case is simply
exposing the even lower level operating system interface.  At that
level, the address family is indeed just an arbitrary integer.

The socket man page on (for example) Solaris-9 says things like, "The
currently understood formats are", and "If a protocol is specified by
the caller, then it will be packaged into a socket level option
request and sent to the underlying pro- tocol layers".  You don't
really know for sure if you used a valid value until the low-level
protocol drivers look at the number you passed in.  This doesn't sound
like an enum to me.

There are plenty of places where we pass around integers that would be
better served by enums.  Address families and protocol numbers in the
socket interface just isn't one of them.




More information about the Python-list mailing list