On Wed, 13 Oct 2021 17:00:49 -0700
Guido van Rossum <gu...@python.org> wrote:
> On Wed, Oct 13, 2021 at 4:56 PM Victor Stinner <vstin...@python.org> wrote:
> 
> > Honestly, I don't understand well the difference between __int__() and
> > __index__().
> >
> > * https://docs.python.org/dev/reference/datamodel.html#object.__int__
> > * https://docs.python.org/dev/reference/datamodel.html#object.__index__
> >  
> 
> If you want to index a list or array 'a' with index 'i', and i is not an
> int already, we try to convert it to int using __index__. This should fail
> for floats, since a[3.14] is a bug. OTOH, int(x) where x is a float should
> And int(s) where s is a string
> should also work, so int() can't call __trunc__ (as was explained earlier
> in the thread).

This seems like a red herring, because str.__int__ is not defined.  The
code to make int(str) work is a separate code path inside
PyNumber_Long().

Note that PyNumber_Long() is now the only place inside the interpreter
calling the `nb_int` slot.  But since it also has those undesirable code
paths accepting str and buffer-like objects, it's usable in fewer
situations than you'd expect.

Regards

Antoine.


_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/3BLOMBMUBTQMOZW7GBZS7DSP25MNOKUX/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to