[Python-ideas] Is there a reason some of the PyLong_As* functions don't call an object's __int__?

Antoine Pitrou solipsis at pitrou.net
Fri Dec 8 06:36:51 EST 2017


On Fri, 8 Dec 2017 13:26:48 +0200
Serhiy Storchaka <storchaka at gmail.com>
wrote:
> 
> > Currently the following functions fall back on __int__ where available:
> > 
> > PyLong_AsLong
> > PyLong_AsLongAndOverflow
> > PyLong_AsLongLong
> > PyLong_AsLongLongAndOverflow
> > PyLong_AsUnsignedLongMask
> > PyLong_AsUnsignedLongLongMask  
> 
> I think this should be deprecated (and there should be an open issue for 
> this). Calling __int__ is just a Python 2 legacy.

I think that's a bad idea.  There are widely-used int-like classes out
there and it will break actual code:

>>> import numpy as np
>>> x = np.int64(5)
>>> isinstance(x, int)
False
>>> x.__int__()
5


Regards

Antoine.




More information about the Python-ideas mailing list