Details
-
Bug
-
Resolution: Duplicate
-
Not Evaluated
-
None
-
6.8.1
-
None
Description
Problem:
When the Callable type hints were updated in 6.8.1, the Slot._call_ method was updated to the following:
class Slot(object):
...
def __call__(self, function: typing.Callable[[typing.Any], typing.Any]) -> typing.Any: ...
This signature indicates that a slot can only receive a single argument despite it actually accepting any number of parameters.
Impact:
Due to this change, the only time the Slot decoration can be used without error is the case where it passes no data. This is because the self parameter required by slot methods counts as the first callable parameter and thus the following snippet would be flagged as an error by static type checkers:
class ErrorExample(QObject):
@Slot(str)
def update_name(self, name: str) -> None: ...
Proposed Solution:
The simplest solution to this issue is to modify the stub for the Slot class as follows:
class Slot(object):
...
def __call__(self, function: typing.Callable[..., typing.Any]) -> typing.Any: ...
Attachments
Issue Links
- duplicates
-
PYSIDE-2942 Type hints: Slot() annotations fails in different cases
-
- Reported
-