Details
-
Suggestion
-
Resolution: Unresolved
-
Not Evaluated
-
None
-
6.8.2
-
None
Description
As you know, PySide6 provides a decorator to help hinting that a specific method is actually a slot.
For example :
class SomeClass2(QObject): @Slot(int, result=str) def f_int_returns_str2(self, i: int) -> str: return 'abc'
Since Slot describes its argument types and return value, an interesting challenge was ... can we make this typesafe ? Can we make mpy check the consistency of information passed to Slot and the actual type information of the method ?
The answer is yes, but it's not so easy.
I attach here :
- the example that should type-check correctly
- an implementation of type-checked Slot()
The implementation is quite heavy because I had to provide type signature for each overload with a diffrent number of arguments and each overload has two variant whether the return value is specified or not.
This was written long before recent improvements in specifying overloads arguments. So there might be a simpler way to achieve this same result today.
Anyway, here you are.