Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix pyqtSlot result parameter type and Callable generic #102

Merged
merged 10 commits into from
Oct 7, 2020
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
* [#51](https://github.com/stlehmann/PyQt5-stubs/pull/51) adds `pyqtBoundSignal.signal` hinted as `str`

### Changed
* [#102](https://github.com/stlehmann/PyQt5-stubs/pull/102) fix `pyqtSlot` parameter typing and overloads
* [#104](https://github.com/stlehmann/PyQt5-stubs/pull/104) `sip.voidptr` handles integer values and sequences and takes `self`
* [#103](https://github.com/stlehmann/PyQt5-stubs/pull/103) `pyqtBoundSignal.disconnect()`'s `slot` parameter is optional
* [#100](https://github.com/stlehmann/PyQt5-stubs/pull/100) fill generic parameter as `sip.array[int]` for QtDataVisualization textures
Expand Down
28 changes: 26 additions & 2 deletions PyQt5-stubs/QtCore.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9235,7 +9235,8 @@ QT_VERSION = ... # type: int
QT_VERSION_STR = ... # type: str


FuncT = typing.TypeVar('FuncT', bound=typing.Callable) # For a correct pyqtSlot annotation
T = typing.TypeVar("T")
FuncT = typing.Callable[..., T]


def qSetRealNumberPrecision(precision: int) -> QTextStreamManipulator: ...
Expand Down Expand Up @@ -9267,7 +9268,30 @@ def oct_(s: QTextStream) -> QTextStream: ...
def bin_(s: QTextStream) -> QTextStream: ...
def Q_RETURN_ARG(type: typing.Any) -> QGenericReturnArgument: ...
def Q_ARG(type: typing.Any, data: typing.Any) -> QGenericArgument: ...
def pyqtSlot(*types: typing.Any, name: typing.Optional[str] = ..., result: typing.Optional[str] = ...) -> typing.Callable[[FuncT], FuncT]: ...
@typing.overload
def pyqtSlot(*types: typing.Any) -> typing.Callable[[FuncT[T]], FuncT[T]]: ...
@typing.overload
def pyqtSlot(*types: typing.Any, name: str) -> typing.Callable[[FuncT[T]], FuncT[T]]: ...
@typing.overload
def pyqtSlot(*types: typing.Any, result: typing.Type[T]) -> typing.Callable[[FuncT[T]], FuncT[T]]: ...
@typing.overload
def pyqtSlot(*types: typing.Any, result: str) -> typing.Callable[[FuncT[T]], FuncT[T]]: ...
@typing.overload
def pyqtSlot(*types: typing.Any, revision: int) -> typing.Callable[[FuncT[T]], FuncT[T]]: ...
@typing.overload
def pyqtSlot(*types: typing.Any, name: str, result: typing.Type[T]) -> typing.Callable[[FuncT[T]], FuncT[T]]: ...
@typing.overload
def pyqtSlot(*types: typing.Any, name: str, result: str) -> typing.Callable[[FuncT[T]], FuncT[T]]: ...
@typing.overload
def pyqtSlot(*types: typing.Any, name: str, revision: int) -> typing.Callable[[FuncT[T]], FuncT[T]]: ...
@typing.overload
def pyqtSlot(*types: typing.Any, result: typing.Type[T], revision: int) -> typing.Callable[[FuncT[T]], FuncT[T]]: ...
@typing.overload
def pyqtSlot(*types: typing.Any, result: str, revision: int) -> typing.Callable[[FuncT[T]], FuncT[T]]: ...
@typing.overload
def pyqtSlot(*types: typing.Any, name: str, result: typing.Type[T], revision: int) -> typing.Callable[[FuncT[T]], FuncT[T]]: ...
@typing.overload
def pyqtSlot(*types: typing.Any, name: str, result: str, revision: int) -> typing.Callable[[FuncT[T]], FuncT[T]]: ...
def QT_TRANSLATE_NOOP(a0: str, a1: str) -> str: ...
def QT_TR_NOOP_UTF8(a0: str) -> str: ...
def QT_TR_NOOP(a0: str) -> str: ...
Expand Down
13 changes: 11 additions & 2 deletions tests/pyqtslot.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
from PyQt5.QtCore import pyqtSlot

@pyqtSlot(str)
def func(s: str) -> int:
def func_none(s: str) -> None:
BryceBeagle marked this conversation as resolved.
Show resolved Hide resolved
return

@pyqtSlot(str, result=int)
def func_int(s: str) -> int:
return 42

func("test")
@pyqtSlot(str, result='int')
def func_str(s: str) -> str:
return '42'

func_none("test")
x = func_int("test") # type: int