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

~QtGui.QTextOption.ShowTabsAndSpaces fails on PySide 6.4 + Windows

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P1: Critical
    • None
    • 6.4.0
    • PySide
    • None
    • Windows
    • 328b8a52e9 (pyside/pyside-setup/dev) bfe91d1d50 (pyside/pyside-setup/6.4.0) 37c377c255 (pyside/pyside-setup/6.4) 37c377c255 (pyside/tqtc-pyside-setup/6.4) 37c377c255 (pyside/tqtc-pyside-setup/tqtc/6.4), 6cf588f61 (dev), 0c582b559 (dev)

    Description

      When using PySide 6.4 on Windows and CPython 3.10, the following code snippet fails:

      from PySide6 import QtGui
      print(~QtGui.QTextOption.ShowTabsAndSpaces)
      

      It raises the following exception:

      File ...\enum.py:928, in Flag.__invert__(self)
          926 for m in self.__class__:
          927     if m not in members and not (m._value_ & self._value_):
      --> 928         inverted = inverted | m
          929 return self.__class__(inverted)
      
      File ...\enum.py:911, in Flag.__or__(self, other)
          909 if not isinstance(other, self.__class__):
          910     return NotImplemented
      --> 911 return self.__class__(self._value_ | other._value_)
      
      File ...\enum.py:385, in EnumMeta.__call__(cls, value, names, module, qualname, type, start)
          360 """
          361 Either returns an existing member, or creates a new enum class.
          362
         (...)
          382 `type`, if set, will be mixed in as the first base class.
          383 """
          384 if names is None:  # simple value lookup
      --> 385     return cls.__new__(cls, value)
          386 # otherwise, functional API: we're creating a new Enum type
          387 return cls._create_(
          388         value,
          389         names,
         (...)
          393         start=start,
          394         )
      
      File ...\enum.py:718, in Enum.__new__(cls, value)
          716         if not isinstance(exc, ValueError):
          717             exc.__context__ = ve_exc
      --> 718         raise exc
          719 finally:
          720     # ensure all variables that could hold an exception are destroyed
          721     exc = None
      
      File ...\enum.py:700, in Enum.__new__(cls, value)
          698 try:
          699     exc = None
      --> 700     result = cls._missing_(value)
          701 except Exception as e:
          702     exc = e
      
      File ...\enum.py:846, in Flag._missing_(cls, value)
          844 if value < 0:
          845     value = ~value
      --> 846 possible_member = cls._create_pseudo_member_(value)
          847 if original_value < 0:
          848     possible_member = ~possible_member
      
      File ...\enum.py:861, in Flag._create_pseudo_member_(cls, value)
          859 _, extra_flags = _decompose(cls, value)
          860 if extra_flags:
      --> 861     raise ValueError("%r is not a valid %s" % (value, cls.__qualname__))
          862 # construct a singleton enum pseudo-member
          863 pseudo_member = object.__new__(cls)
      
      ValueError: 2147483617 is not a valid QTextOption.Flag
      

      The problem seems to be the incorrect conversion from the int value for IncludeTrailingSpaces. It's -2147483648 on Windows, and 2147483648 on Linux:

      In [3]: QtGui.QTextOption.Flag.__members__
      Out[3]:
      mappingproxy({'ShowTabsAndSpaces': <Flag.ShowTabsAndSpaces: 1>,
                    'ShowLineAndParagraphSeparators': <Flag.ShowLineAndParagraphSeparators: 2>,
                    'AddSpaceForLineAndParagraphSeparators': <Flag.AddSpaceForLineAndParagraphSeparators: 4>,
                    'SuppressColors': <Flag.SuppressColors: 8>,
                    'ShowDocumentTerminator': <Flag.ShowDocumentTerminator: 16>,
                    'IncludeTrailingSpaces': <Flag.IncludeTrailingSpaces: -2147483648>})
      

      The tested code snippet works in the following environments:

      • PySide 6.3, Windows + CPython 3.10.4
      • PySide 6.4, Ubuntu 22.04 + CPython 3.10.6

      from

         enum Flag {
              ShowTabsAndSpaces = 0x1,
              ShowLineAndParagraphSeparators = 0x2,
              AddSpaceForLineAndParagraphSeparators = 0x4,
              SuppressColors = 0x8,
              ShowDocumentTerminator = 0x10,
              IncludeTrailingSpaces = 0x80000000
          };
      

      Attachments

        1. pyside2088.py
          0.5 kB
          Friedemann Kleint
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            kleint Friedemann Kleint
            ltfish Fish Wang
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: