[PyQt] Floats being accepted for int arguments

Florian Bruhin me at the-compiler.org
Tue Nov 27 09:51:39 GMT 2018


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:

  >>> 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?

Florian

-- 
https://www.qutebrowser.org | me at the-compiler.org (Mail/XMPP)
   GPG: 916E B0C8 FD55 A072 | https://the-compiler.org/pubkey.asc
         I love long mails! | https://email.is-not-s.ms/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20181127/369ed3f1/attachment.sig>


More information about the PyQt mailing list