--- a/eric6/Project/ProjectBaseBrowser.py Thu Apr 15 16:52:05 2021 +0200 +++ b/eric6/Project/ProjectBaseBrowser.py Thu Apr 15 18:11:24 2021 +0200 @@ -8,6 +8,7 @@ """ import os +import contextlib from PyQt5.QtCore import ( QModelIndex, pyqtSignal, Qt, QCoreApplication, QItemSelectionModel, @@ -591,12 +592,10 @@ childIndex = self.model().index(0, 0) while childIndex.isValid(): if self.isExpanded(childIndex): - try: + with contextlib.suppress(AttributeError): expandedNames.append( self.model().item(childIndex).name()) - except AttributeError: # only items defining the name() method are returned - pass childIndex = self.indexBelow(childIndex) return expandedNames @@ -611,13 +610,11 @@ for name in names: childIndex = model.index(0, 0) while childIndex.isValid(): - try: + with contextlib.suppress(AttributeError): if model.item(childIndex).name() == name: self.setExpanded(childIndex, True) break - except AttributeError: # ignore items not supporting this method - pass childIndex = self.indexBelow(childIndex) def _prepareRepopulateItem(self, name):