Skip to content

Commit 2455093

Browse files
committed
Fix: Suppress AttributeError tracebacks during widget teardown on Python 3.14 / Qt6
During widget destruction, Qt still delivers events and calls size-hint methods on QwtPlot objects whose Python __dict__ has already been cleared, so accessing private instance attributes raises an uncaught AttributeError. This produced noisy "Unhandled exception" tracebacks at pytest teardown for several subclasses (BasePlot, LevelsHistogram, XCrossSectionPlot, YCrossSectionPlot), reporting 'object has no attribute _QwtPlot__data'. * [FIX] : Guard access to self.__data.canvas in QwtPlot.eventFilter with try/except AttributeError, delegating to QFrame.eventFilter on failure * [FIX] : Guard access to self.__data.layout in QwtPlot.minimumSizeHint with try/except AttributeError, returning an empty QSize() on failure
1 parent 64a9401 commit 2455093

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

qwt/plot.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,12 @@ def event(self, event):
10071007
return QFrame.event(self, event)
10081008

10091009
def eventFilter(self, obj, event):
1010-
if obj is self.__data.canvas:
1010+
try:
1011+
canvas = self.__data.canvas
1012+
except AttributeError:
1013+
# The plot is being destroyed: Python attributes already cleared
1014+
return QFrame.eventFilter(self, obj, event)
1015+
if obj is canvas:
10111016
if event.type() == QEvent.Resize:
10121017
self.updateCanvasMargins()
10131018
elif event.type() == 178: # QEvent.ContentsRectChange:
@@ -1195,7 +1200,12 @@ def minimumSizeHint(self):
11951200
"""
11961201
:return: Return a minimum size hint
11971202
"""
1198-
hint = self.__data.layout.minimumSizeHint(self)
1203+
try:
1204+
layout = self.__data.layout
1205+
except AttributeError:
1206+
# The plot is being destroyed: Python attributes already cleared
1207+
return QSize()
1208+
hint = layout.minimumSizeHint(self)
11991209
hint += QSize(2 * self.frameWidth(), 2 * self.frameWidth())
12001210
return hint
12011211

0 commit comments

Comments
 (0)