[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 05:59:04 EST 2017

On Fri, 8 Dec 2017 11:41:10 +0100
Erik Bray <erik.m.bray at gmail.com> wrote:
> I ran into this because I was passing an object that implements
> __int__ to the maxlen argument to deque().  On Python 2 this used
> PyInt_AsSsize_t which does fall back to calling __int__, whereas
> PyLong_AsSsize_t does not.

It should probably call PyNumber_AsSsize_t instead (which will call
__index__, which is the right thing here).

> I think this inconsistency should be fixed, unless there's some reason
> for it I'm not seeing.

That sounds reasonable to me.



More information about the Python-ideas mailing list