IceSpringPySideStubs icon indicating copy to clipboard operation
IceSpringPySideStubs copied to clipboard

BUG: `bytes = str` creates errors

Open adam-grant-hendry opened this issue 3 years ago • 0 comments

In nearly all stub files in this package, bytes has been overwritten by str as follows:

bytes = str

This incorrectly allows mypy to pass statements such as

from PySide6 import QtCore

animation = QtCore.QPropertyAnimation(
    QtWidgets.QWidget(),
    'maximumHeight',
)

that yield errors in python because the function expects either a QByteArray object or a bytes object:

TypeError: 'PySide6.QtCore.QPropertyAnimation.__init__' called with wrong argument types:
  PySide6.QtCore.QPropertyAnimation.__init__(QWidget, str)
Supported signatures:
  PySide6.QtCore.QPropertyAnimation.__init__(Union[PySide6.QtCore.QObject, NoneType] = None)
  PySide6.QtCore.QPropertyAnimation.__init__(PySide6.QtCore.QObject, Union[PySide6.QtCore.QByteArray, bytes], Union[PySide6.QtCore.QObject, NoneType] = None)

If instead a byte string is used, then mypy incorrectly assumes this is a Literal:

Argument of type "Literal[b'maximumHeight']" cannot be assigned to parameter "propertyName" of type "QByteArray | bytes" in function "__init__"
  Type "Literal[b'maximumHeight']" cannot be assigned to type "QByteArray | bytes"
    "Literal[b'maximumHeight']" is incompatible with "QByteArray"
    "Literal[b'maximumHeight']" is incompatible with "bytes"Pylance(reportGeneralTypeIssues)

Solution

Remove the line

bytes = str

everywhere it appears in all the stubs.

Thanks for the great package!

adam-grant-hendry avatar Jun 16 '22 00:06 adam-grant-hendry