I'm trying to use the inspect
module to determine the Signature
of methods and I'm running into a problem with PyQt widgets. The widgets report a signature containing *args
and **kwargs
, but cannot be called with arbitrary keyword arguments:
>>> from PyQt5.QtWidgets import QWidget, QApplication
>>> from inspect import signature
>>> signature(QWidget.__init__)
<Signature (self, /, *args, **kwargs)>
>>> app = QApplication([])
>>> QWidget(c=10)
TypeError: 'c' is an unknown keyword argument
However, VSCode seems to be able to tell what the actual signature of the method is, as it correctly autofills calls or overrides:
QWidget(
and:
class MyWidget(QWidget):
def __init__
autocompletes the overriden __init__
method to:
def __init__(self, parent: ,, flags: ,) -> None:
super().__init__(parent=parent, flags=flags)
Is there a way I can actually get this correct signature of PyQt5's widget methods in my code?