Skip to content

Commit 70238e1

Browse files
authored
Merge pull request #102 from altendky/pyqtslot_fixup
fix `pyqtSlot` `result` parameter type and `Callable` generic
2 parents 121dc88 + bf51e07 commit 70238e1

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1515
* [#51](https://github.com/stlehmann/PyQt5-stubs/pull/51) adds `pyqtBoundSignal.signal` hinted as `str`
1616

1717
### Changed
18+
* [#102](https://github.com/stlehmann/PyQt5-stubs/pull/102) fix `pyqtSlot` parameter typing and overloads
1819
* [#104](https://github.com/stlehmann/PyQt5-stubs/pull/104) `sip.voidptr` handles integer values and sequences and takes `self`
1920
* [#103](https://github.com/stlehmann/PyQt5-stubs/pull/103) `pyqtBoundSignal.disconnect()`'s `slot` parameter is optional
2021
* [#100](https://github.com/stlehmann/PyQt5-stubs/pull/100) fill generic parameter as `sip.array[int]` for QtDataVisualization textures

PyQt5-stubs/QtCore.pyi

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9235,7 +9235,8 @@ QT_VERSION = ... # type: int
92359235
QT_VERSION_STR = ... # type: str
92369236

92379237

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

92409241

92419242
def qSetRealNumberPrecision(precision: int) -> QTextStreamManipulator: ...
@@ -9267,7 +9268,30 @@ def oct_(s: QTextStream) -> QTextStream: ...
92679268
def bin_(s: QTextStream) -> QTextStream: ...
92689269
def Q_RETURN_ARG(type: typing.Any) -> QGenericReturnArgument: ...
92699270
def Q_ARG(type: typing.Any, data: typing.Any) -> QGenericArgument: ...
9270-
def pyqtSlot(*types: typing.Any, name: typing.Optional[str] = ..., result: typing.Optional[str] = ...) -> typing.Callable[[FuncT], FuncT]: ...
9271+
@typing.overload
9272+
def pyqtSlot(*types: typing.Any) -> typing.Callable[[FuncT[T]], FuncT[T]]: ...
9273+
@typing.overload
9274+
def pyqtSlot(*types: typing.Any, name: str) -> typing.Callable[[FuncT[T]], FuncT[T]]: ...
9275+
@typing.overload
9276+
def pyqtSlot(*types: typing.Any, result: typing.Type[T]) -> typing.Callable[[FuncT[T]], FuncT[T]]: ...
9277+
@typing.overload
9278+
def pyqtSlot(*types: typing.Any, result: str) -> typing.Callable[[FuncT[T]], FuncT[T]]: ...
9279+
@typing.overload
9280+
def pyqtSlot(*types: typing.Any, revision: int) -> typing.Callable[[FuncT[T]], FuncT[T]]: ...
9281+
@typing.overload
9282+
def pyqtSlot(*types: typing.Any, name: str, result: typing.Type[T]) -> typing.Callable[[FuncT[T]], FuncT[T]]: ...
9283+
@typing.overload
9284+
def pyqtSlot(*types: typing.Any, name: str, result: str) -> typing.Callable[[FuncT[T]], FuncT[T]]: ...
9285+
@typing.overload
9286+
def pyqtSlot(*types: typing.Any, name: str, revision: int) -> typing.Callable[[FuncT[T]], FuncT[T]]: ...
9287+
@typing.overload
9288+
def pyqtSlot(*types: typing.Any, result: typing.Type[T], revision: int) -> typing.Callable[[FuncT[T]], FuncT[T]]: ...
9289+
@typing.overload
9290+
def pyqtSlot(*types: typing.Any, result: str, revision: int) -> typing.Callable[[FuncT[T]], FuncT[T]]: ...
9291+
@typing.overload
9292+
def pyqtSlot(*types: typing.Any, name: str, result: typing.Type[T], revision: int) -> typing.Callable[[FuncT[T]], FuncT[T]]: ...
9293+
@typing.overload
9294+
def pyqtSlot(*types: typing.Any, name: str, result: str, revision: int) -> typing.Callable[[FuncT[T]], FuncT[T]]: ...
92719295
def QT_TRANSLATE_NOOP(a0: str, a1: str) -> str: ...
92729296
def QT_TR_NOOP_UTF8(a0: str) -> str: ...
92739297
def QT_TR_NOOP(a0: str) -> str: ...

tests/pyqtslot.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
from PyQt5.QtCore import pyqtSlot
22

33
@pyqtSlot(str)
4-
def func(s: str) -> int:
4+
def func_none(s: str) -> None:
5+
return
6+
7+
@pyqtSlot(str, result=int)
8+
def func_int(s: str) -> int:
59
return 42
610

7-
func("test")
11+
@pyqtSlot(str, result='int')
12+
def func_str(s: str) -> str:
13+
return '42'
14+
15+
func_none("test")
16+
x = func_int("test") # type: int

0 commit comments

Comments
 (0)