raising AttributeError in __getattr__ instead of NameError is the correct way of handling non-existent attributes; otherwise for example hasattr(obj, attribute) would raise NameError instead of returning False if the attribute does not exist

This commit is contained in:
vladimir-kraus 2017-08-04 11:32:21 +02:00
parent 30864df76d
commit 668973bd44
2 changed files with 2 additions and 2 deletions

View File

@ -48,7 +48,7 @@ class TabWindow(QtGui.QMainWindow):
if hasattr(self.cw, attr):
return getattr(self.cw, attr)
else:
raise NameError(attr)
raise AttributeError(attr)
class PlotWindow(PlotWidget):

View File

@ -76,7 +76,7 @@ class PlotWidget(GraphicsView):
m = getattr(self.plotItem, attr)
if hasattr(m, '__call__'):
return m
raise NameError(attr)
raise AttributeError(attr)
def viewRangeChanged(self, view, range):
#self.emit(QtCore.SIGNAL('viewChanged'), *args)