Wrong type annotation of pyqtSlot in PyQt5
Phil Thompson
phil at riverbankcomputing.com
Fri Sep 22 10:12:09 BST 2023
On 22/09/2023 07:28, Alexander Hedges wrote:
> On Thu, Sep 21, 2023 at 6:31 PM Phil Thompson
> <phil at riverbankcomputing.com> wrote:
>>
>> 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
>
> Oh, this is interesting. So the correct definition is indeed on line
> 67. But it turns out
> that there is a second incorrect definition of pyqtSlot (the one
> above) on line 9972
> of QtCore.pyi. This line probably just needs removal.
Done.
Thanks,
Phil
More information about the PyQt
mailing list