Details
Description
First issue
Consider the following minimal working example:
import sys from PySide6.QtWidgets import QWidget, QMainWindow, QApplication class SomeClass: __slots__ = ('_a',) def __init__(self) -> None: self._a: int = 0 self._b: int = 0 # AttributeError class MainWindow(QMainWindow): __slots__ = ('_a',) def __init__(self, parent: QWidget | None = None) -> None: super().__init__(parent) self._a: int = 0 self._b: int = 0 # where is AttributeError? if __name__ == '__main__': # test = SomeClass() # AttributeError app = QApplication(sys.argv) mainWindow = MainWindow() mainWindow.show() sys.exit(app.exec())
As an example, if `SomeClass` is instantiated, an `AttributeError` will be raised since `b` is not defined in `slots`. The issue is that if `slots` are defined inside a class that derives a Qt class (for example, the `MainWindow` class shown above), an `AttributeError` is no longer raised. It seems as tho defining `slots` does nothing.
Second issue
Consider the following minimal working example:
import sys from PySide6.QtWidgets import QWidget, QMainWindow, QApplication class MainWindowShell(QMainWindow): __slots__ = ('_a',) # results in a crash def __init__(self, parent: QWidget | None = None) -> None: super().__init__(parent) self._a: int = 0 class MainWindow(MainWindowShell): __slots__ = () # this does nothing def __init__(self, parent: QWidget | None = None) -> None: super().__init__(parent) if __name__ == '__main__': app = QApplication(sys.argv) mainWindow = MainWindow() mainWindow.show() sys.exit(app.exec())
In this example the application will crash (or not launch). Defining `slots` inside a class that derives a Qt class will crash the application if that class serves as a base class.
Attachments
Issue Links
- relates to
-
PYSIDE-1970 Using __slots__ in PySide subclasses segfaults
- Closed