Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-2977

Callable type hint for Slot is over constrained

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • Not Evaluated
    • None
    • 6.8.1
    • PySide, Type hints
    • 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

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              crmaurei Cristian Maureira-Fredes
              bflecker Bryton Flecker
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes