--- a/eric6/UI/BrowserModel.py Tue Sep 24 18:46:24 2019 +0200 +++ b/eric6/UI/BrowserModel.py Tue Sep 24 19:08:10 2019 +0200 @@ -12,8 +12,10 @@ import fnmatch import json -from PyQt5.QtCore import QDir, QModelIndex, QAbstractItemModel, \ - QFileSystemWatcher, Qt, QProcess, QCoreApplication +from PyQt5.QtCore import ( + QDir, QModelIndex, QAbstractItemModel, QFileSystemWatcher, Qt, QProcess, + QCoreApplication +) from PyQt5.QtGui import QImageReader, QFont from PyQt5.QtWidgets import QApplication @@ -94,8 +96,10 @@ item = index.internalPointer() if index.column() < item.columnCount(): return item.data(index.column()) - elif index.column() == item.columnCount() and \ - index.column() < self.columnCount(self.parent(index)): + elif ( + index.column() == item.columnCount() and + index.column() < self.columnCount(self.parent(index)) + ): # This is for the case where an item under a multi-column # parent doesn't have a value for all the columns return "" @@ -155,8 +159,12 @@ # The model/view framework considers negative values out-of-bounds, # however in python they work when indexing into lists. So make sure # we return an invalid index for out-of-bounds row/col - if row < 0 or column < 0 or \ - row >= self.rowCount(parent) or column >= self.columnCount(parent): + if ( + row < 0 or + column < 0 or + row >= self.rowCount(parent) or + column >= self.columnCount(parent) + ): return QModelIndex() if not parent.isValid(): @@ -269,9 +277,11 @@ """ if isinstance(itm, BrowserDirectoryItem): dirName = itm.dirName() - if dirName != "" and \ - not dirName.startswith("//") and \ - not dirName.startswith("\\\\"): + if ( + dirName != "" and + not dirName.startswith("//") and + not dirName.startswith("\\\\") + ): if dirName not in self.watcher.directories(): self.watcher.addPath(dirName) if dirName in self.watchedItems: @@ -559,8 +569,8 @@ Utilities.toNativeSeparators(f.absoluteFilePath()), False) else: - fileFilters = \ - Preferences.getUI("BrowsersFileFilters").split(";") + fileFilters = Preferences.getUI( + "BrowsersFileFilters").split(";") if fileFilters: fn = f.fileName() if any(fnmatch.fnmatch(fn, ff.strip()) @@ -658,16 +668,18 @@ QCoreApplication.translate("BrowserModel", "Imports")) self._addItem(node, parentItem) if "@@Import@@" in keys: - for importedModule in \ - dictionary["@@Import@@"].getImports().values(): + for importedModule in ( + dictionary["@@Import@@"].getImports().values() + ): m_node = BrowserImportItem( node, importedModule.importedModuleName, importedModule.file, importedModule.linenos) self._addItem(m_node, node) - for importedName, linenos in \ - importedModule.importedNames.items(): + for importedName, linenos in ( + importedModule.importedNames.items() + ): mn_node = BrowserImportItem( m_node, importedName, @@ -987,8 +999,11 @@ BrowserItem.__init__(self, parent, dn) self.type_ = BrowserItemDirectory - if not Utilities.isDrive(self._dirName) and \ - os.path.lexists(self._dirName) and os.path.islink(self._dirName): + if ( + not Utilities.isDrive(self._dirName) and + os.path.lexists(self._dirName) and + os.path.islink(self._dirName) + ): self.symlink = True self.icon = UI.PixmapCache.getSymlinkIcon("dirClosed.png") else: @@ -1163,9 +1178,13 @@ """ self._filename = os.path.abspath(finfo) self.itemData[0] = os.path.basename(finfo) - if self.isPython2File() or self.isPython3File() or \ - self.isRubyFile() or self.isIdlFile() or \ - self.isProtobufFile(): + if ( + self.isPython2File() or + self.isPython3File() or + self.isRubyFile() or + self.isIdlFile() or + self.isProtobufFile() + ): self._dirName = os.path.dirname(finfo) self._moduleName = os.path.basename(finfo) @@ -1215,9 +1234,11 @@ @return flag indicating a Python file (boolean) """ - return self.fileext in Preferences.getPython("PythonExtensions") or \ + return ( + self.fileext in Preferences.getPython("PythonExtensions") or (self.fileext == "" and self.sourceLanguage in ["Python", "Python2"]) + ) def isPython3File(self): """ @@ -1225,8 +1246,10 @@ @return flag indicating a Python file (boolean) """ - return self.fileext in Preferences.getPython("Python3Extensions") or \ + return ( + self.fileext in Preferences.getPython("Python3Extensions") or (self.fileext == "" and self.sourceLanguage == "Python3") + ) def isRubyFile(self): """ @@ -1234,8 +1257,10 @@ @return flag indicating a Ruby file (boolean) """ - return self.fileext == '.rb' or \ + return ( + self.fileext == '.rb' or (self.fileext == "" and self.sourceLanguage == "Ruby") + ) def isDesignerFile(self): """ @@ -1324,8 +1349,10 @@ @return flag indicating a D file (boolean) """ - return self.fileext in ['.d', '.di'] or \ + return ( + self.fileext in ['.d', '.di'] or (self.fileext == "" and self.sourceLanguage == "D") + ) def lessThan(self, other, column, order): """ @@ -1342,8 +1369,8 @@ if issubclass(other.__class__, BrowserFileItem): sinit = os.path.basename(self._filename).startswith('__init__.py') - oinit = \ - os.path.basename(other.fileName()).startswith('__init__.py') + oinit = os.path.basename(other.fileName()).startswith( + '__init__.py') if sinit and not oinit: return order == Qt.AscendingOrder if not sinit and oinit: @@ -1421,10 +1448,12 @@ self.icon = UI.PixmapCache.getIcon("class_protected.png") else: self.icon = UI.PixmapCache.getIcon("class.png") - if self._classObject and \ - (self._classObject.methods or - self._classObject.classes or - self._classObject.attributes): + if ( + self._classObject and + (self._classObject.methods or + self._classObject.classes or + self._classObject.attributes) + ): self._populated = False self._lazyPopulation = True @@ -1477,12 +1506,16 @@ @param order sort order (Qt.SortOrder) (for special sorting) @return true, if this item is less than other (boolean) """ - if issubclass(other.__class__, BrowserCodingItem) or \ - issubclass(other.__class__, BrowserClassAttributesItem): + if issubclass( + other.__class__, + (BrowserCodingItem, BrowserClassAttributesItem) + ): return order == Qt.DescendingOrder - if Preferences.getUI("BrowsersListContentsByOccurrence") and \ - column == 0: + if ( + Preferences.getUI("BrowsersListContentsByOccurrence") and + column == 0 + ): if order == Qt.AscendingOrder: return self.lineno() < other.lineno() else: @@ -1519,11 +1552,15 @@ self._name = name self._functionObject = fn self._filename = filename - if self._functionObject.modifier == \ - Utilities.ClassBrowsers.ClbrBaseClasses.Function.Static: + if ( + self._functionObject.modifier == + Utilities.ClassBrowsers.ClbrBaseClasses.Function.Static + ): self.icon = UI.PixmapCache.getIcon("method_static.png") - elif self._functionObject.modifier == \ - Utilities.ClassBrowsers.ClbrBaseClasses.Function.Class: + elif ( + self._functionObject.modifier == + Utilities.ClassBrowsers.ClbrBaseClasses.Function.Class + ): self.icon = UI.PixmapCache.getIcon("method_class.png") elif self._functionObject.isPrivate(): self.icon = UI.PixmapCache.getIcon("method_private.png") @@ -1540,8 +1577,10 @@ # ....format(name, # ", ".join([e.split('=')[0].strip() # for e in self._functionObject.parameters])) - if self._functionObject and \ - (self._functionObject.methods or self._functionObject.classes): + if ( + self._functionObject and + (self._functionObject.methods or self._functionObject.classes) + ): self._populated = False self._lazyPopulation = True @@ -1602,8 +1641,10 @@ elif issubclass(other.__class__, BrowserClassAttributesItem): return order == Qt.DescendingOrder - if Preferences.getUI("BrowsersListContentsByOccurrence") and \ - column == 0: + if ( + Preferences.getUI("BrowsersListContentsByOccurrence") and + column == 0 + ): if order == Qt.AscendingOrder: return self.lineno() < other.lineno() else: @@ -1680,8 +1721,10 @@ """ if issubclass(other.__class__, BrowserCodingItem): return order == Qt.DescendingOrder - elif issubclass(other.__class__, BrowserClassItem) or \ - issubclass(other.__class__, BrowserMethodItem): + elif issubclass( + other.__class__, + (BrowserClassItem, BrowserMethodItem) + ): return order == Qt.AscendingOrder return BrowserItem.lessThan(self, other, column, order) @@ -1762,8 +1805,10 @@ @param order sort order (Qt.SortOrder) (for special sorting) @return true, if this item is less than other (boolean) """ - if Preferences.getUI("BrowsersListContentsByOccurrence") and \ - column == 0: + if ( + Preferences.getUI("BrowsersListContentsByOccurrence") and + column == 0 + ): if order == Qt.AscendingOrder: return self.lineno() < other.lineno() else: @@ -1812,9 +1857,10 @@ @param order sort order (Qt.SortOrder) (for special sorting) @return true, if this item is less than other (boolean) """ - if issubclass(other.__class__, BrowserClassItem) or \ - issubclass(other.__class__, BrowserClassAttributesItem) or \ - issubclass(other.__class__, BrowserImportItem): + if issubclass( + other.__class__, + (BrowserClassItem, BrowserClassAttributesItem, BrowserImportItem) + ): return order == Qt.AscendingOrder return BrowserItem.lessThan(self, other, column, order) @@ -1845,8 +1891,10 @@ @param order sort order (Qt.SortOrder) (for special sorting) @return true, if this item is less than other (boolean) """ - if issubclass(other.__class__, BrowserClassItem) or \ - issubclass(other.__class__, BrowserClassAttributesItem): + if issubclass( + other.__class__, + (BrowserClassItem, BrowserClassAttributesItem) + ): return order == Qt.AscendingOrder return BrowserItem.lessThan(self, other, column, order) @@ -1912,8 +1960,10 @@ @param order sort order (Qt.SortOrder) (for special sorting) @return true, if this item is less than other (boolean) """ - if Preferences.getUI("BrowsersListContentsByOccurrence") and \ - column == 0: + if ( + Preferences.getUI("BrowsersListContentsByOccurrence") and + column == 0 + ): if order == Qt.AscendingOrder: return self.lineno() < other.lineno() else: