[PyQt] Floats accepted for C++ ints?
Phil Thompson
phil at riverbankcomputing.com
Tue Jul 5 18:33:37 BST 2016
On 5 Jul 2016, at 6:22 pm, Florian Bruhin <me at the-compiler.org> wrote:
>
> I've noticed Python floats are accepted when a C++ int is expected,
> and simply truncated:
>
> >>> from PyQt5.QtCore import QRect
> >>> QRect(0.5, 0.5, 0.5, 0.5)
> PyQt5.QtCore.QRect()
> >>> QRect(1.5, 1.5, 1.5, 1.5)
> PyQt5.QtCore.QRect(1, 1, 1, 1)
>
> Is this intended behaviour? I'd have expected to raise a TypeError
> (or, if anything, accept floats where .is_integer() is true)
It's standard Python behaviour. Floats implement __int__().
Phil
More information about the PyQt
mailing list