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

Proper type hints for Qt.KeyboardModifier and Qt.Modifier

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • P4: Low
    • None
    • None
    • Type hints
    • None

    Description

      If you attempt to type check the following code:

      from PySide6.QtCore import Qt
      
      x = Qt.KeyboardModifier.KeypadModifier | Qt.Key.Key_0
      

      you'll get the following error:

      x.py:42: error: Unsupported operand types for | ("KeyboardModifier" and "Key")  [operator]
          x = Qt.KeyboardModifier.KeypadModifier | Qt.Key.Key_0
                                                   ^~~~~~~~~~~~
      Found 1 error in 1 file (checked 1 source file)
      

      I propose adding the following to QtCore.pyi (but I'm not sure how to submit a PR here )

      class _SupportsOrKey(enum.Flag):
          @overload
          def __or__(self, other: Self) -> Qt.KeyboardModifier: ...
          @overload
          def __or__(self, other: Qt.Key) -> QKeyCombination: ...
          @overload
          def __ror__(self, other: Self) -> Qt.KeyboardModifier: ...
          @overload
          def __ror__(self, other: Qt.Key) -> QKeyCombination: ...
      
      class Qt(Shiboken.Object):
          class KeyboardModifier(_SupportsOrKey):
              ...
          class Modifier(_SupportsOrKey):
              ...
      

      Attachments

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

        Activity

          People

            crmaurei Cristian Maureira-Fredes
            talley Talley Lambert
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes