pyqt on python 3.10 - implicit float to int conversion issue

Erik Hvatum ice.rikh at gmail.com
Mon Jun 13 17:28:03 BST 2022


Thank you for this link <https://bugs.python.org/issue36048>. I had
wondered why lots of production code using PyQt was breaking upon updating
old Linux installations, but I simply had no time to look into it and froze
Python package versions, thinking it's the usual stuff with Guido van
Rossum doing *things.*

The PySide6 behavior described by Mark Dickinson in your link seems ideal,
to me. Here's my vote for making PyQt adopt the same behavior.

It is appropriate for an interface to a C++ library, because C++ does and
always will do implicit float / int conversion, except when explicitly
forbidden by use of asserts with the type_traits library, overloads, etc.

Thanks,
Erik

On Mon, Jun 13, 2022 at 10:57 AM meta <0x0meta at gmail.com> wrote:

> Hello,
>
> When using PyQt with previous versions of Python, a float can be passed
> where an int is expected e.g. QColor(0, 0, 0, 255 * some_float).
>
> With 3.10 however, the same code gives the following error:
> ```
> TypeError: arguments did not match any overloaded call:
>   QColor(Qt.GlobalColor): argument 1 has unexpected type 'int'
>   QColor(int): too many arguments
>   QColor(QRgba64): argument 1 has unexpected type 'int'
>   QColor(Any): too many arguments
>   QColor(): too many arguments
>   QColor(int, int, int, alpha: int = 255): argument 4 has unexpected type
> 'float'
>   QColor(str): argument 1 has unexpected type 'int'
>   QColor(Union[QColor, Qt.GlobalColor, QGradient]): argument 1 has
> unexpected type 'int'
> ```
>
> Specifically `QColor(int, int, int, alpha: int = 255): argument 4 has
> unexpected type 'float'`.
>
> I believe this is related to the following deprecation in 3.8 which was
> solidified in 3.10: https://bugs.python.org/issue36048
>
> Cheers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20220613/0f03ca8c/attachment.htm>


More information about the PyQt mailing list