[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: Re: [PyQt] Floats being accepted for int arguments
From: Phil Thompson <phil () riverbankcomputing ! com>
Date: 2018-11-27 10:15:08
Message-ID: C4C4BB86-E8EB-489B-B71F-9562139BF5D1 () riverbankcomputing ! com
[Download RAW message or body]
On 27 Nov 2018, at 9:51 am, Florian Bruhin <me@the-compiler.org> wrote:
>
> Hi,
>
> turns out running mypy on a big PyQt codebase results in some things to
> talk about :D
>
> Apparently, PyQt accepts floats where C++ takes ints and silently
> truncates them:
>
>>>> from PyQt5.QtGui import QFont
>>>> f = QFont()
>>>> f.setWeight(5.8)
>>>> f.weight()
> 5
>
> Similar Python methods usually accept floats if f.is_integer() is true,
> but raise a ValueError otherwise:
I disagree with "usually".
>>>> import math
>>>> math.factorial(5)
> 120
>>>> math.factorial(5.0)
> 120
>>>> math.factorial(5.5)
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> ValueError: factorial() only accepts integral values
>
> Is that behavior intended?
It calls PyLong_AsLongLong(), so yes.
Phil
_______________________________________________
PyQt mailing list PyQt@riverbankcomputing.com
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic