fixed recursive PlotWidget.__getattr__ calls#2860
Conversation
pyqtgraph/widgets/PlotWidget.py
Outdated
| m = getattr(self.plotItem, attr) | ||
| if hasattr(m, '__call__'): | ||
| return m | ||
| except: |
There was a problem hiding this comment.
Can you specify which exception to catch here instead of the bare exception?
There was a problem hiding this comment.
Well, in fact, no need to modify the implementation of PlotWidget.__getattr__. Moreover, the problem has nothing to do with multiple inheritance. It comes from the fact that the PlotWidget.__getattr__ tries to access the PlotItem attribute before it actually exists - generating recursive calls to PlotWidget.__getattr__ while trying to access self.PlotItem.
The simplest solution is to instantiate the PlotItem attribute at the very beginning of the PlotWidget.__init__ and we are done withe the problem.
def __init__ (self, parent=None, background='default', plotItem=None, **kargs):
## start by instantiating the plotItem attribute in order to avoid recursive
## calls to PlotWidget.__getattr__ - which accesses self.plotItem!
self.plotItem = None
...
PR modified.
|
Love the modified PR, creating the attribute at initialization is a good way to go; not sure why we just don't instantiate the PlotItem instance at |
|
BTW, when do you plan to publish a new release? |
|
Haha probably soon as we have fixed issues with recent bindings. I
introduced a bug in the SVG exporter I want to fix first. Been doing a lot
of travel (recreational and for work) recently which has really put a
damper on things. I don’t have any scheduled travel for a while… so
hopefully in a week or two.
…On Sun, Oct 29, 2023 at 12:24 Nicolas Leclercq ***@***.***> wrote:
BTW, when do you plan to publish a new release?
—
Reply to this email directly, view it on GitHub
<#2860 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAE5Z7VPOK52FIORLW7IMY3YB2NOHAVCNFSM6AAAAAA6T3KJ4WVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTOOBUGIYDGMJQGU>
.
You are receiving this because you modified the open/close state.Message
ID: ***@***.***>
|
PlotWidget.__getattr__ implicitly wrap methods from PlotItem. However, the current implementation leads to recursive calls
and 'maximum recursion depth exceeded' errors when PlotWidget is used in a multiple inheritance schema - i.e., class SomeClass(PlotWidget, SomeOtherClass). The proposed PlotWidget.__getattr__ prevents the recursive calls by get rid of the hasattr that is the source of the problem.