Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MNT: Move some calls to children classes to stop pyside6 throwing an error about __init__ in classes that use multiple inheritence. #1181

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

nstelter-slac
Copy link
Collaborator

@nstelter-slac nstelter-slac commented Mar 4, 2025

There is no issue running on pyqt5, but on pyside6 throws a runtime error when initializing classes that use multiple inheritance of a qt base class and a pydm class.

example class:

    class PyDMDrawing(QWidget, PyDMWidget, new_properties=_penRuleProperties))
    ...
    def __init__(self, parent=None, init_channel=None):
       ...
       # explicitly calling base class __init__ functions
       QWidget.__init__(self, parent)
       PyDMWidget.__init__(self, init_channel=init_channel)
       ...

The runtime error happens when a call is made in the base class that relies on the qt base class's __init__ call to have completed setting things up (such as 'installEventFilter()).

example error:

    -> self.installEventFilter(self)
    RuntimeError: '__init__' method of object's base class (PyDMDrawingImage) not called

This error is thrown despite that we explicitly call each of it's base class __init__ functions. It seems like pyside6 is just being extra cautious here.

The fix here is to move these "problem" calls out of our pydm base classes __init__ and into the children class's __init__, after we explicity call the parent class constructors. To match the functionality of b4, these calls need to be added to any classes with PyDMWidget as their parent.

…classes with multiple inheritence not getting called, when we actually are

calling them.

There is no issue running on pyqt5, but on pyside6 throws a runtime error when initializing classes
that use multiple inheritance of a qt base class and a pydm class.

example class:
    class PyDMDrawing(QWidget, PyDMWidget, new_properties=_penRuleProperties))
    ...
    def __init__(self, parent=None, init_channel=None):
       ...
       # explicitly calling base class __init__ functions
       QWidget.__init__(self, parent)
       PyDMWidget.__init__(self, init_channel=init_channel)
       ...

The runtime error happens when a call is made in the base class that
relies on the qt base class's __init__ call to have completed setting
things up (such as 'installEventFilter()).

example error:
    -> self.installEventFilter(self)
    RuntimeError: '__init__' method of object's base class (PyDMDrawingImage) not called.

This error is thrown despite that we explicitly call each of it's base class __init__
functions. It seems like pyside6 is just being extra cautious here.

The fix here is to move these "problem" calls out of our pydm base
classes __init__ and into the children class's __init__, after we explicity
call the parent class constructors. To match the functionality of b4,
these calls need to be added to any classes with PyDMWidget as their
parent.
@nstelter-slac nstelter-slac changed the title MNT: Deal with pyside6 throwing an error about __init__ functions in … MNT: Move some calls to children classes to stop pyside6 throwing an error about __init__ in classes with multiple inheritence , when we actually are calling them. Mar 4, 2025
@nstelter-slac nstelter-slac changed the title MNT: Move some calls to children classes to stop pyside6 throwing an error about __init__ in classes with multiple inheritence , when we actually are calling them. MNT: Move some calls to children classes to stop pyside6 throwing an error about __init__ in classes that use multiple inheritence , when we actually are calling them. Mar 4, 2025
@nstelter-slac nstelter-slac changed the title MNT: Move some calls to children classes to stop pyside6 throwing an error about __init__ in classes that use multiple inheritence , when we actually are calling them. MNT: Move some calls to children classes to stop pyside6 throwing an error about __init__ in classes that use multiple inheritence. Mar 4, 2025
@nstelter-slac
Copy link
Collaborator Author

this patch addresses the same issue discussed here: #1177

@nstelter-slac nstelter-slac added the pyside6 for adding pyside6 (qt6) support label Mar 13, 2025
@YektaY
Copy link
Collaborator

YektaY commented Mar 13, 2025

Have you looked to see if __init_subclass__ could work in this case? https://peps.python.org/pep-0487/

@nstelter-slac
Copy link
Collaborator Author

nstelter-slac commented Mar 13, 2025

Have you looked to see if _init_subclass_ could work in this case? https://peps.python.org/pep-0487/

yes i messed around a bit with _init_subclass_, but it seems like it only gets called at subclass creation time (as opposed to subclass instance creation time).

meaning we get access to "cls" but not "self", so in it we could only modify class attributes like 'RULE_PROPERTIES', which are vars shared across all instances of the class

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pyside6 for adding pyside6 (qt6) support
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants