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

Can't properly type hint a custom signal in my Protocol class

XMLWordPrintable

    • Icon: Suggestion Suggestion
    • Resolution: Unresolved
    • Icon: P3: Somewhat important P3: Somewhat important
    • None
    • 6.x
    • Type hints
    • None
    • All

      So, I have a Protocol class named Game:

      from typing import Any, Protocol
      
      class Game(Protocol):
          """Protocol for implementing a specific chess game."""
      
          move_played: Any  # ClassVar[Signal[Move]]  (Move is from python-chess library)
      

      There's no way to annotate my move_played signal so that mypy would be happy. I thought ClassVar[Signal] would be okay, but no such luck. Also, I'd like to annotate that the instance of Signal will carry a Move object.

      The concrete class defines it like this:

      class ClassicGame(QObject):
          """Implementation of a classic chess game."""
      
          move_played: Signal = Signal(Move)
      

      Please help me add a proper type hint to my move_played custom signal in my Protocol class.

      Please note that

      ClassVar[Signal] = ...
      

      is also fruitless.

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

            ctismer Christian Tismer
            pedantichacker Boštjan Mejak
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:

                There are no open Gerrit changes