Open
Description
So I don't know that this pans out but here's a very preliminary proof of concept that my initial thoughts were wrong and this is at least vaguely possible without a mypy plugin. It doesn't deal with the variadic nature of signal parameters nor does it make any attempt at #9. Anyways, I just wrote it up out of curiosity so figured I'd share it here. Though it may still require a mypy plugin to actually get it working right. Oh yeah, also doesn't cover connecting to a proper 'slot'.
Based on the signal classes in #56.
https://mypy-play.net/?mypy=latest&python=3.8&flags=strict&gist=fb8771c87a891edcfa30d522ae588638
import typing
TA = typing.TypeVar("TA")
TB = typing.TypeVar("TB")
class pyqtBoundSignal(typing.Generic[TA, TB]):
signal: str = ""
def emit(self, a: TA, b: TB) -> None: ...
class pyqtSignal(typing.Generic[TA, TB]):
def __init__(self, a: typing.Type[TA], b: typing.Type[TB], *, name: str = ...) -> None: ...
@typing.overload
def __get__(self, instance: None, owner: object) -> "pyqtSignal": ...
@typing.overload
def __get__(self, instance: object, owner: object) -> pyqtBoundSignal[TA, TB]: ...
def __get__(self, instance, owner):
# mypy-play doesn't seem to offer a 'stub' option
pass
class D:
signal = pyqtSignal(int, str)
d = D()
d.signal.emit(1, "s")
d.signal.emit(1, 2)
main.py:33: error: Argument 2 to "emit" of "pyqtBoundSignal" has incompatible type "int"; expected "str"
Found 1 error in 1 file (checked 1 source file)