PyQt6 v6.12.0 stubs - positional-only parameters missing "/"

Grzegorz Bokota g.bokota at mimuw.edu.pl
Fri Oct 16 13:45:53 BST 2026


Will the solution also contain also change of naming in type stubs to not
use a0, a1 etc but use proper descriptive names like "watched" and "event"
from Qt documentation?
https://doc.qt.io/qt-6/qobject.html#eventFilter bool
QObject::eventFilter(QObject *watched, QEvent *event)

Is it also possible to stop providing annotations like QObject | None for
call parameters, even if Qt documentation suggests that it can't be None
(also when checking PySide6 documentation, they provide plan QObject)?
I see that it comes from Qt convention to pass objects as pointers, not
references, but in reality I don't seen calling an event handler with None
in place of Event. But type checkers still complain that the None case is
not supported, which leads to writing obsolete code.

Regards,
Grzegorz Bokota

czw., 15 paź 2026 o 23:26 Phil Thompson <phil at riverbankcomputing.com>
napisał(a):

> On 12/10/2026 21:18, Dragan A. wrote:
> > Hi,
> >
> > One more stub issue, this time a general one.
> >
> > At runtime, PyQt methods don't accept required arguments as keywords:
> >
> >     obj.eventFilter(a0=o, a1=e)  ->  TypeError: eventFilter() takes no
> > keyword arguments
> >     obj.event(a0=e)              ->  TypeError: event() takes no
> > keyword
> > arguments
> >
> > But the stubs declare them as normal parameters, without "/":
> >
> >     def eventFilter(self, a0: 'QObject|None', a1: 'QEvent|None') ->
> > bool:
> > ...
> >
> > Because of that, type checkers treat the names a0/a1 as part of the
> > API, and
> > every override that uses meaningful names is reported as incompatible
> > (pyright 1.1.414):
> >
> >     class Filter(QObject):
> >         def eventFilter(self, watched: QObject | None, event: QEvent |
> > None) -> bool: ...
> >
> >     error: Method "eventFilter" overrides class "QObject" in an
> > incompatible manner
> >       Parameter 2 name mismatch: base parameter is named "a0", override
> > parameter is named "watched"
> >
> > Users are forced to name their parameters a0, a1, ... or add ignore
> > comments.
> > The stubs themselves already contradict this: QObject.eventFilter uses
> > (a0, a1), while some QtWidgets overrides use (watched, event), (object,
> > event)
> > or (o, e).
> >
> > The fix is to emit "/" after the arguments that can't be passed as
> > keywords:
> >
> >     def eventFilter(self, a0: 'QObject|None', a1: 'QEvent|None', /) ->
> > bool: ...
> >     def event(self, a0: 'QEvent|None', /) -> bool: ...
> >
> > This matches the runtime behavior and lets subclasses use any parameter
> > names.
> > It applies to all generated methods, not only eventFilter.
> >
> > Best regards,
>
> This will be fixed in the next SIP snapshot.
>
> Thanks,
> Phil
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20261016/4d4867a3/attachment.htm>


More information about the PyQt mailing list