Wrong type annotation of pyqtSlot in PyQt5

Phil Thompson phil at riverbankcomputing.com
Thu Sep 21 17:31:10 BST 2023


On 21/09/2023 11:01, Alexander Hedges wrote:
> Hi,
> 
> Currently in PyQt5 (as of the latest development build) the pyqtSlot 
> decorator
> is typed as:
> 
> ```python
> def pyqtSlot(*args: typing.Any, name: typing.Optional[str] = ...,
> result: typing.Optional[str] = ...) -> typing.Callable[...,
> typing.Optional[str]]: ...
> ```
> 
> Which is an incorrect annotation given that this function is a 
> decorator (it
> should return a function that takes a function and returns a function).
> 
> In PyQt6 this is currently correctly annotated as returning a function 
> that
> takes a function and returns a function with the same signature:
> 
> ```python
> FuncT = typing.TypeVar('FuncT', bound=typing.Callable)
> def pyqtSlot(*types, name: typing.Optional[str] = ..., result:
> typing.Optional[str] = ...) -> typing.Callable[[FuncT], FuncT]: ...
> ```
> 
> It would be great if you could fix the stub file in PyQt5.

In the latest snapshots...

https://www.riverbankcomputing.com/pypi/simple/pyqt5/

...it is identical to PyQt6.

Phil


More information about the PyQt mailing list