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

Reg->6.8.1: Importing PySide6 modifies typing.Self

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • Not Evaluated
    • None
    • 6.8.1, 6.8.2, 6.9.0, 6.9.1, 6.8.3
    • Type hints
    • None
    • All

    Description

      environment details:

      OS: Ubuntu 22.04.3 LTS

      Python: <=3.10 (tested on 3.10 & 3.9)

      PySide6: >=3.8.1 (tested on 6.8.1, 6.8.2, 6.8.3, 6.9.0, 6.9.1)

      Description and Examples:

      importing PySide6 modifies the built-in typing module, adding Self to it.

      A small reproducible example:

      import typing
      print(hasattr(typing, "Self"))
      import PySide6 # noqa
      print(hasattr(typing, "Self")) 
      

       

      Python 3.10
      hasattr(typing, "Self")= False
      import PySide6
      hasattr(typing, "Self")= True
      Qt 6.8.1 (x86_64-little_endian-lp64 shared (dynamic) release build; by GCC 10.3.1 20210422 (Red Hat 10.3.1-1)) [Python limited API 3.10.14]
      
      Python 3.10
      hasattr(typing, "Self")= False
      import PySide6
      hasattr(typing, "Self")= False
      Qt 6.8.0 (x86_64-little_endian-lp64 shared (dynamic) release build; by GCC 10.3.1 20210422 (Red Hat 10.3.1-1)) [Python limited API 3.10.14]
      

      I encountered this phenomenon when it broke the usage of another library, cloudphatlib:

      >>> import PySide6
      >>> import cloudpathlib
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
        File ".../lib/python3.10/site-packages/cloudpathlib/__init__.py", line 3, in <module>
          from .anypath import AnyPath
        File ".../lib/python3.10/site-packages/cloudpathlib/anypath.py", line 6, in <module>
          from .cloudpath import InvalidPrefixError, CloudPath
        File ".../lib/python3.10/site-packages/cloudpathlib/cloudpath.py", line 218, in <module>
          class CloudPath(metaclass=CloudPathMeta):
        File ".../lib/python3.10/site-packages/cloudpathlib/cloudpath.py", line 238, in CloudPath
          cloud_path: Union[str, Self, "CloudPath"],
        File ".../lib/python3.10/typing.py", line 312, in inner
          return func(*args, **kwds)
        File ".../lib/python3.10/typing.py", line 403, in __getitem__
          return self._getitem(self, parameters)
        File ".../lib/python3.10/typing.py", line 515, in Union
          parameters = tuple(_type_check(p, msg) for p in parameters)
        File ".../lib/python3.10/typing.py", line 515, in <genexpr>
          parameters = tuple(_type_check(p, msg) for p in parameters)
        File ".../lib/python3.10/typing.py", line 171, in _type_check
          raise TypeError(f"Plain {arg} is not valid as type argument")
      TypeError: Plain typing.Self is not valid as type argument 

      Notice that changing the imports order (i.e., importing cloudphatlib first), it works. 

      Attachments

        1. pyside3135.py
          0.3 kB
          Friedemann Kleint

        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
              noamgot Noam Gottlieb
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes