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

Flag types are unhashable

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Not Evaluated
    • 6.4.0
    • 6.3.0
    • PySide
    • None

    Description

      Reporting this separately from PYSIDE-1906 because this isn't just an unexposed Qt thing, but something that seems unintended.

      Individual PySide enum members are hashable:

      >>> hash(Qt.Key_A)
      65
      

      and so are individual flags:

      >>> hash(Qt.ControlModifier)
      67108864
      >>> type(Qt.ControlModifier)
      <class 'PySide6.QtCore.Qt.KeyboardModifier'>
      >>> type(Qt.ControlModifier).__mro__
      (<class 'PySide6.QtCore.Qt.KeyboardModifier'>, <class 'Shiboken.Enum'>, <class 'object'>)
      

      but as soon as flags get combined, they are unhashable:

      >>> hash(Qt.ControlModifier | Qt.ShiftModifier)
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
      TypeError: unhashable type: 'PySide6.QtCore.Qt.KeyboardModifiers'
      >>> type(Qt.ControlModifier | Qt.ShiftModifier)
      <class 'PySide6.QtCore.Qt.KeyboardModifiers'>
      >>> type(Qt.ControlModifier | Qt.ShiftModifier).__mro__
      (<class 'PySide6.QtCore.Qt.KeyboardModifiers'>, <class 'object'>)
      

      despite still being an unique int, i.e., trivially hashable:

      >>> int(Qt.ControlModifier | Qt.ShiftModifier)
      100663296
      

      Attachments

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

        Activity

          People

            Unassigned Unassigned
            the compiler Florian Bruhin
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes