[issue36048] Deprecate implicit truncating when convert Python numbers to C integers: use __index__, not __int__

Oleg Iarygin report at bugs.python.org
Thu Dec 9 02:32:08 EST 2021


Oleg Iarygin <oleg at arhadthedev.net> added the comment:

The reporter gave more details (<https://github.com/python/cpython/pull/11952#issuecomment-989430968>):

> Literally this is ok in C++ with Qt:
>
>     float x = 2.3, y = 1.1;
>     auto p = QPoint(x, y); // QPoint only takes 2 int params.. this works in C++; floats can be always be implicitly converted to int
>
> Same code, more or less, in Python3.10 is now broken:
>
>     x = 2.3
>     y = 1.1
>     p = QPoint(x, y)  # This fails, where previously it worked on every Python version since the age of the dinosaurs...
>
> Note that most of the API for PyQt5 is auto-generated from the function signatures of the C++. So in this case QPoint takes 2 ints for its c'tor (just like in C++).. and breaks on Python 3.10 if given floats, when previously it worked just fine with either ints or floats. This is just 1 example. But many codebases that use PyQt5 are hit by breakages like this one now.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue36048>
_______________________________________


More information about the Python-bugs-list mailing list