Bug 2025599 - python-pyside2 fails to build with Python 3.11: error: expression is not assignable
Summary: python-pyside2 fails to build with Python 3.11: error: expression is not assi...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: python-pyside2
Version: rawhide
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Richard Shaw
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
: 2099081 (view as bug list)
Depends On:
Blocks: PYTHON3.11 F37FTBFS F37FailsToInstall 2098704 2098744 2099067 2099088 2099131 2099184
TreeView+ depends on / blocked
 
Reported: 2021-11-22 14:55 UTC by Tomáš Hrnčiar
Modified: 2022-07-06 20:29 UTC (History)
11 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2022-07-01 10:42:13 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Tomáš Hrnčiar 2021-11-22 14:55:01 UTC
python-pyside2 fails to build with Python 3.11.0a2.

/builddir/build/BUILD/pyside-setup-opensource-src-5.15.2/sources/shiboken2/libshiboken/basewrapper.cpp:369:23: error: expression is not assignable
        Py_TYPE(type) = SbkObjectType_TypeF();
        ~~~~~~~~~~~~~ ^
/builddir/build/BUILD/pyside-setup-opensource-src-5.15.2/sources/shiboken2/libshiboken/basewrapper.cpp:515:5: warning: 'UsingDeprecatedTrashcanMacro' is deprecated [-Wdeprecated-declarations]
    Py_TRASHCAN_SAFE_BEGIN(pyObj);
    ^
/usr/include/python3.11/cpython/object.h:547:9: note: expanded from macro 'Py_TRASHCAN_SAFE_BEGIN'
        UsingDeprecatedTrashcanMacro cond=1; \
        ^
/usr/include/python3.11/cpython/object.h:544:1: note: 'UsingDeprecatedTrashcanMacro' has been explicitly marked deprecated here
Py_DEPRECATED(3.11) typedef int UsingDeprecatedTrashcanMacro;
^
/usr/include/python3.11/pyport.h:392:54: note: expanded from macro 'Py_DEPRECATED'
#define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
                                                     ^
/builddir/build/BUILD/pyside-setup-opensource-src-5.15.2/sources/shiboken2/libshiboken/basewrapper.cpp:1113:23: error: expression is not assignable
    Py_TYPE(heaptype) = SbkObjectType_TypeF();
    ~~~~~~~~~~~~~~~~~ ^
1 warning and 2 errors generated.

Since Py_TYPE() is changed to a inline static function, Py_TYPE(obj) = new_type must be replaced with Py_SET_TYPE(obj, new_type): see the Py_SET_TYPE() function (available since Python 3.9). For backward compatibility, this macro can be used:

#if PY_VERSION_HEX < 0x030900A4 && !defined(Py_SET_TYPE)
static inline void _Py_SET_TYPE(PyObject *ob, PyTypeObject *type)
{ ob->ob_type = type; }
#define Py_SET_TYPE(ob, type) _Py_SET_TYPE((PyObject*)(ob), type)
#endif

(Contributed by Victor Stinner in bpo-39573.)

https://bugs.python.org/issue39573
https://docs.python.org/3.11/whatsnew/3.11.html

For the build logs, see:
https://copr-be.cloud.fedoraproject.org/results/@python/python3.11/fedora-rawhide-x86_64/02979239-python-pyside2/

For all our attempts to build python-pyside2 with Python 3.11, see:
https://copr.fedorainfracloud.org/coprs/g/python/python3.11/package/python-pyside2/

Testing and mass rebuild of packages is happening in copr. You can follow these instructions to test locally in mock if your package builds with Python 3.11:
https://copr.fedorainfracloud.org/coprs/g/python/python3.11/

Let us know here if you have any questions.

Python 3.11 is planned to be included in Fedora 37. To make that update smoother, we're building Fedora packages with all pre-releases of Python 3.11.
A build failure prevents us from testing all dependent packages (transitive [Build]Requires), so if this package is required a lot, it's important for us to get it fixed soon.
We'd appreciate help from the people who know this package best, but if you don't want to work on this now, let us know so we can try to work around it on our side.

Comment 1 Richard Shaw 2021-12-05 22:15:07 UTC
This is a first for me... I setup the mock config but when I try to run it I get this:

Start: dnf install
Traceback (most recent call last):
  File "/usr/bin/dnf", line 57, in <module>
    from dnf.cli import main
  File "/usr/lib/python3.10/site-packages/dnf/__init__.py", line 30, in <module>
    import dnf.base
  File "/usr/lib/python3.10/site-packages/dnf/base.py", line 32, in <module>
    from dnf.comps import CompsQuery
  File "/usr/lib/python3.10/site-packages/dnf/comps.py", line 27, in <module>
    from dnf.exceptions import CompsError
  File "/usr/lib/python3.10/site-packages/dnf/exceptions.py", line 22, in <module>
    import dnf.util
  File "/usr/lib/python3.10/site-packages/dnf/util.py", line 29, in <module>
    import dnf.callback
  File "/usr/lib/python3.10/site-packages/dnf/callback.py", line 22, in <module>
    import dnf.yum.rpmtrans
  File "/usr/lib/python3.10/site-packages/dnf/yum/rpmtrans.py", line 26, in <module>
    import rpm
ModuleNotFoundError: No module named 'rpm'

Comment 2 Miro Hrončok 2021-12-05 23:12:20 UTC
Pass --no-bootstrap-chroot to mock please.

Comment 3 Richard Shaw 2021-12-06 04:14:28 UTC
Not sure why that's needed but updating to the latest version worked.

Comment 4 Miro Hrončok 2021-12-06 09:42:18 UTC
Mock by default uses a bootstrap chroot which uses dnf from our Copr repo and dnf is not yet available/working there.

As a result of a previous incident, some of the packages in copr have insufficient Requires, so python3-rpm from Python 3.11 was happily installed with dnf from Rawhide into the bootstrap chroot. We are in the process of fixing this.

Comment 5 Richard Shaw 2021-12-06 13:26:47 UTC
Whoops, closed the wrong bug. python-collada is fixed, not this package.

Comment 6 Richard Shaw 2021-12-07 20:12:20 UTC
I've fixed the above error but now I'm getting something that's completely confusing me:

/builddir/build/BUILD/pyside-setup-opensource-src-5.15.2/redhat-linux-build/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/parser.py:199: RuntimeWarning: pyside_type_init:

        UNRECOGNIZED:   'zero(Any)'
        OFFENDING LINE: 'PySide2.QtCore.QSettings.value(self,arg__1:QString,defaultValue:QVariant=0,type:PyObject=0)->PyObject'
        
  warnings.warn("""pyside_type_init:
Traceback (most recent call last):
  File "/builddir/build/BUILD/pyside-setup-opensource-src-5.15.2/sources/pyside2/PySide2/QtCore/../support/generate_pyi.py", line 326, in <module>
    generate_all_pyi(outpath, options=options)
  File "/builddir/build/BUILD/pyside-setup-opensource-src-5.15.2/sources/pyside2/PySide2/QtCore/../support/generate_pyi.py", line 305, in generate_all_pyi
    generate_pyi(import_name, outpath, options)
  File "/builddir/build/BUILD/pyside-setup-opensource-src-5.15.2/sources/pyside2/PySide2/QtCore/../support/generate_pyi.py", line 241, in generate_pyi
    HintingEnumerator(fmt).module(import_name)
  File "/builddir/build/BUILD/pyside-setup-opensource-src-5.15.2/redhat-linux-build/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/lib/enum_sig.py", line 95, in module
    ret.update(self.klass(class_name, klass))
  File "/builddir/build/BUILD/pyside-setup-opensource-src-5.15.2/redhat-linux-build/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/lib/enum_sig.py", line 129, in klass
    signature = getattr(thing, "__signature__", None)
  File "/builddir/build/BUILD/pyside-setup-opensource-src-5.15.2/redhat-linux-build/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/loader.py", line 97, in pyside_type_init
    return parser.pyside_type_init(type_key, sig_strings)
  File "/builddir/build/BUILD/pyside-setup-opensource-src-5.15.2/redhat-linux-build/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/parser.py", line 447, in pyside_type_init
    props = calculate_props(line)
  File "/builddir/build/BUILD/pyside-setup-opensource-src-5.15.2/redhat-linux-build/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/parser.py", line 344, in calculate_props
    annotations["return"] = (_resolve_type(returntype, line, 0, handle_retvar)
  File "/builddir/build/BUILD/pyside-setup-opensource-src-5.15.2/redhat-linux-build/sources/shiboken2/shibokenmodule/files.dir/shibokensupport/signature/parser.py", line 280, in _resolve_type
    return eval(result, namespace)
  File "<string>", line 1, in <module>
  File "/usr/lib64/python3.10/typing.py", line 1182, in __getitem__
    return self.__getitem_inner__(params)
  File "/usr/lib64/python3.10/typing.py", line 309, in inner
    return func(*args, **kwds)
  File "/usr/lib64/python3.10/typing.py", line 1188, in __getitem_inner__
    result = _type_check(result, msg)
  File "/usr/lib64/python3.10/typing.py", line 169, in _type_check
    raise TypeError(f"Plain {arg} is not valid as type argument")
TypeError: Plain typing.Optional is not valid as type argument

And this is with f35... I tried starting with f34 to ensure building completes, and it does, and am now working my way up to rawhide.

Comment 7 Petr Viktorin (pviktori) 2022-01-21 15:40:29 UTC
Can you share your changes so far so I can poke around?
Do you know what is being eval'd in parser.py:280?
Or which file is being parsed here?

I can get this error by parametrizing types using typing.Optional, e.g.

>>> import typing
>>> typing.List[typing.Optional]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python3.10/typing.py", line 311, in inner
    return func(*args, **kwds)
  File "/usr/lib64/python3.10/typing.py", line 1123, in __getitem__
    params = tuple(_type_check(p, msg) for p in params)
  File "/usr/lib64/python3.10/typing.py", line 1123, in <genexpr>
    params = tuple(_type_check(p, msg) for p in params)
  File "/usr/lib64/python3.10/typing.py", line 171, in _type_check
    raise TypeError(f"Plain {arg} is not valid as type argument")
TypeError: Plain typing.Optional is not valid as type argument

To be usable, Optional itself needs to be parametrized, e.g. typing.List[typing.Optional[int]]
But I don't know how the PySide build got here.

Comment 8 Petr Viktorin (pviktori) 2022-01-21 16:46:48 UTC
Ah, maybe I found it!
It seems shiboken relies on "special forms" like Optional not having __name__, which they got in Python 3.10.
In `to_string` in shibokensupport/signature/parser.py, try replacing:
     if hasattr(thing, "__name__"):    
with:
     if hasattr(thing, "__name__") and not hasattr(thing, "__args__"):

Comment 9 Ben Cotton 2022-02-08 21:09:03 UTC
This bug appears to have been reported against 'rawhide' during the Fedora 36 development cycle.
Changing version to 36.

Comment 10 Miro Hrončok 2022-06-20 10:19:42 UTC
*** Bug 2099081 has been marked as a duplicate of this bug. ***

Comment 11 Sergio Basto 2022-06-21 22:03:49 UTC
(In reply to Tomáš Hrnčiar from comment #0)
> python-pyside2 fails to build with Python 3.11.0a2.
> 
> /builddir/build/BUILD/pyside-setup-opensource-src-5.15.2/sources/shiboken2/
> libshiboken/basewrapper.cpp:369:23: error: expression is not assignable
>         Py_TYPE(type) = SbkObjectType_TypeF();
>         ~~~~~~~~~~~~~ ^
> /builddir/build/BUILD/pyside-setup-opensource-src-5.15.2/sources/shiboken2/
> libshiboken/basewrapper.cpp:515:5: warning: 'UsingDeprecatedTrashcanMacro'
> is deprecated [-Wdeprecated-declarations]
>     Py_TRASHCAN_SAFE_BEGIN(pyObj);
>     ^
> /usr/include/python3.11/cpython/object.h:547:9: note: expanded from macro
> 'Py_TRASHCAN_SAFE_BEGIN'
>         UsingDeprecatedTrashcanMacro cond=1; \
>         ^
> /usr/include/python3.11/cpython/object.h:544:1: note:
> 'UsingDeprecatedTrashcanMacro' has been explicitly marked deprecated here
> Py_DEPRECATED(3.11) typedef int UsingDeprecatedTrashcanMacro;
> ^
> /usr/include/python3.11/pyport.h:392:54: note: expanded from macro
> 'Py_DEPRECATED'
> #define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
>                                                      ^
> /builddir/build/BUILD/pyside-setup-opensource-src-5.15.2/sources/shiboken2/
> libshiboken/basewrapper.cpp:1113:23: error: expression is not assignable
>     Py_TYPE(heaptype) = SbkObjectType_TypeF();
>     ~~~~~~~~~~~~~~~~~ ^
> 1 warning and 2 errors generated.
> 
> Since Py_TYPE() is changed to a inline static function, Py_TYPE(obj) =
> new_type must be replaced with Py_SET_TYPE(obj, new_type): see the
> Py_SET_TYPE() function (available since Python 3.9). For backward
> compatibility, this macro can be used:
> 
> #if PY_VERSION_HEX < 0x030900A4 && !defined(Py_SET_TYPE)
> static inline void _Py_SET_TYPE(PyObject *ob, PyTypeObject *type)
> { ob->ob_type = type; }
> #define Py_SET_TYPE(ob, type) _Py_SET_TYPE((PyObject*)(ob), type)
> #endif
> 
> (Contributed by Victor Stinner in bpo-39573.)
> 
> https://bugs.python.org/issue39573
> https://docs.python.org/3.11/whatsnew/3.11.html

we have about 170 Py_TYPE in code [1]  

here [2] is suggest that `Py_TYPE(ob)` can be replaced with `ob->ob_type` , am I right ? 


[1] 
ack Py_TYPE  | wc -l
181

[2]
https://github.com/python/cpython/issues/91768#issue-1210326060

Comment 12 Henrik Nordström 2022-06-23 15:06:59 UTC
There is ongoing release with initial python-3.11 support.

https://wiki.qt.io/Qt_for_Python_Development_Notes

Comment 13 Sergio Basto 2022-06-23 15:44:25 UTC
(In reply to Henrik Nordström from comment #12)
> There is ongoing release with initial python-3.11 support.
> 
> https://wiki.qt.io/Qt_for_Python_Development_Notes

and where is the source code of Qt_for_Python or patches available ?

Comment 14 Miro Hrončok 2022-06-23 23:05:48 UTC
I've opened https://src.fedoraproject.org/rpms/python-pyside2/pull-request/9

But it fails on me with:

[ 50%] Built target QtGui
gmake[1]: Leaving directory '/builddir/build/BUILD/pyside-setup-opensource-src-5.15.2/redhat-linux-build'
gmake: *** [Makefile:139: all] Error 2

There is no compiler error above that :/

Comment 15 Miro Hrončok 2022-06-23 23:19:23 UTC
This cannot build on power due to bz2100546. This is not the only problem, but if we fix everything else, that will block.

Comment 16 Henrik Nordström 2022-06-27 13:57:20 UTC
(In reply to Sergio Basto from comment #13)

> and where is the source code of Qt_for_Python or patches available ?

Don't think there is any patches available, or a ready release for Python 3.11 yet. Was just to notify that upstream is actively working on it. And is very possible that work is only done on PySide6.

https://download.qt.io/official_releases/QtForPython/pyside2/ has several releases after the latest release. Don't know their status.

GIT repo is at https://code.qt.io/cgit/pyside/pyside-setup.git/

Project home page at https://wiki.qt.io/Qt_for_Python

Comment 17 Fedora Update System 2022-06-28 15:54:55 UTC
FEDORA-2022-3ab3f9bdbc has been submitted as an update to Fedora 37. https://bodhi.fedoraproject.org/updates/FEDORA-2022-3ab3f9bdbc

Comment 18 Fedora Update System 2022-06-28 15:58:00 UTC
FEDORA-2022-3ab3f9bdbc has been pushed to the Fedora 37 stable repository.
If problem still persists, please make note of it in this bug report.

Comment 19 Ben Beasley 2022-06-28 15:59:15 UTC
Sorry, it looks like I tagged the wrong bug in a usd update. Reopening.

Comment 20 Miro Hrončok 2022-06-30 12:26:41 UTC
The fix is ready in https://src.fedoraproject.org/rpms/python-pyside2/pull-request/10 but this package cannot build due to bz2100546.

Comment 21 Miro Hrončok 2022-07-01 10:42:13 UTC
Hello,

Please note that this comment was generated automatically. If you feel that this output has mistakes, please contact me via email (mhroncok).

All subpackages of a package against which this bug was filled are now installable or removed from Fedora 37.

Thanks for taking care of it!

Comment 22 Fedora Update System 2022-07-06 20:27:05 UTC
FEDORA-2022-e4f83ff98e has been submitted as an update to Fedora 37. https://bodhi.fedoraproject.org/updates/FEDORA-2022-e4f83ff98e

Comment 23 Fedora Update System 2022-07-06 20:29:57 UTC
FEDORA-2022-e4f83ff98e has been pushed to the Fedora 37 stable repository.
If problem still persists, please make note of it in this bug report.


Note You need to log in before you can comment on or make changes to this bug.