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

mypy error on @Slot() annotated methods

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • Not Evaluated
    • None
    • 6.8.2
    • PySide, Type hints
    • None

    Description

      in the current packaged version of PySide6 you can find, in .venv/lib/python3.13/site-packages/PySide6/QtCore.pyi the following definition for Slot :

      class Slot(object):
          def __init__(self, /, *types: type, name: str | None= ..., result: type | None= ...) -> None: ...
          def __call__(self, function: typing.Callable[[typing.Any], typing.Any], /) -> typing.Any: ...
      

      this definition, however, makes mypy raise errors if Slot annotates a method. For example, see on mypy play - also here:

      import typing
      
      class Slot(object):
      
          def __init__(self, /, *types: type, name: str | None= ..., result: type | None= ...) -> None: ...
      
          def __call__(self, function: typing.Callable[[typing.Any], typing.Any], /) -> typing.Any: ...
      
      class Foo:
          @Slot(str)
          def bar(self, mystr: str) -> None:
              pass
      

      you will get the error:

      main.py:10: error: Argument 1 to "_call_" of "Slot" has incompatible type "Callable[[Foo, str], None]"; expected "Callable[[Any], Any]" [arg-type]

       

      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
              zeed Vito De Tullio
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes