[Python-es] None < 0 ???

Rafael Villar Burke pachi en rvburke.com
Jue Ene 3 02:51:18 CET 2008


Rafael Villar Burke wrote:
> Chema Cortes wrote:
>   
>> Es curioso que None tenga su contraparte en el singleton
>> 'NotImplemented', actuando de forma contraria a None (o sea,
>> NotImplemented siempre es mayor que cualquier número). ¿Existe algún
>> motivo para estos comportamientos?
>>     
> Mirando el código, por curiosidad, veo esto sobre Py_None:
>
> //*
> _Py_NoneStruct is an object of undefined type which can be used in contexts
> where NULL (nil) is not suitable (since NULL often means 'error').
>
> Don't forget to apply Py_INCREF() when returning this value!!!
> *//
> *PyAPI_DATA*(PyObject) _Py_NoneStruct; //* Don't use this directly *//
> #*define* Py_None (&_Py_NoneStruct)
>
>
> Así que, tal vez, NotImplemented use NULL para señalar un error y PyNone
> su opuesto.
Y Py_NotImplemented está a continuación:

//*
_Py_NoneStruct is an object of undefined type which can be used in contexts
where NULL (nil) is not suitable (since NULL often means 'error').

Don't forget to apply Py_INCREF() when returning this value!!!
*//
*PyAPI_DATA*(PyObject) _Py_NoneStruct; //* Don't use this directly *//
#*define* Py_None (&_Py_NoneStruct)

//* Macro for returning Py_None from a function *//
#*define* Py_RETURN_NONE return Py_INCREF(Py_None), Py_None

//*
Py_NotImplemented is a singleton used to signal that an operation is
not implemented for a given type combination.


*//
*PyAPI_DATA*(PyObject) _Py_NotImplementedStruct; //* Don't use this directly *//
#*define* Py_NotImplemented (&_Py_NotImplementedStruct)



http://svn.python.org/view/python/trunk/Include/object.h?rev=59564&view=markup

¿Tal vez sea simplemente una cuestión dependiente del compilador...?

Saludos,

Rafael Villar Burke


Más información sobre la lista de distribución Python-es