Closed mdickinson closed 1 year ago
Using .value
instead of int
seems to work for this particular version of PySide6. (But it probably fails for other versions.)
>>> from pyface.qt import QtCore
>>> QtCore.Qt.DockWidgetArea.LeftDockWidgetArea
<DockWidgetArea.LeftDockWidgetArea: 1>
>>> int(QtCore.Qt.DockWidgetArea.LeftDockWidgetArea)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: int() argument must be a string, a bytes-like object or a number, not 'DockWidgetArea'
>>> type(QtCore.Qt.DockWidgetArea.LeftDockWidgetArea).__mro__
(<enum 'DockWidgetArea'>, <enum 'Flag'>, <enum 'Enum'>, <class 'object'>)
>>> QtCore.Qt.DockWidgetArea.LeftDockWidgetArea.value
1
And this is indeed new with PySide6 6.4.0. With 6.3.2, I get:
>>> from pyface.qt import QtCore
>>> int(QtCore.Qt.DockWidgetArea.LeftDockWidgetArea)
1
>>> QtCore.Qt.DockWidgetArea.LeftDockWidgetArea.value
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'PySide6.QtCore.Qt.DockWidgetArea' object has no attribute 'value'
>>>
Looks like matplotlib ran into this too: https://github.com/matplotlib/matplotlib/issues/24155 (fix in https://github.com/matplotlib/matplotlib/pull/24158)
This also begs the question about why we were casting to int
in the first place in the above code.
A bit of digging shows it was to work around a PySide 1.0 bug: https://github.com/enthought/pyface/pull/11
We can possibly remove all of the int(...)
casts introduced by that PR?
We can possibly remove all of the
int(...)
casts introduced by that PR?
Yes, a solution that just treats all Qt Enum values as black-box immutable value objects and doesn't try to interpret them in any way sounds like the ideal fix. (But I could see situations where that wouldn't work - e.g., if we need to serialise and deserialise enum values for some reason.)
The immediate issue is resolved by pinning in #1169
I am going to close this in favour of #1164, with a reference back to the discussion here.
Environment
OS: Mac Python version: 3.8 Toolkit: Qt Qt API: PySide6
Description
Importing
pyface.tasks.api
fails with the latest Pyface (7.4.2) from PyPI and the latest PySide6 (6.4.0).Steps to Reproduce
pip install pyface PySide6
pyface.tasks.api
.The result of the import is a traceback with tail end:
Here's the full session: