diff --git a/nw/__init__.py b/nw/__init__.py index 24214e0c..33d36450 100644 --- a/nw/__init__.py +++ b/nw/__init__.py @@ -240,12 +240,12 @@ def main(sysArgs=None): try: import PyQt5.QtSvg - except: + except ImportError: errorData.append("Python module 'PyQt5.QtSvg' is missing.") try: import lxml - except: + except ImportError: errorData.append("Python module 'lxml' is missing.") if errorData: diff --git a/nw/common.py b/nw/common.py index 5d81a75b..2f5fca4e 100644 --- a/nw/common.py +++ b/nw/common.py @@ -38,7 +38,7 @@ def checkString(checkValue, defaultValue, allowNone=False): """Check if a variable is a string or a none. """ if allowNone: - if checkValue == None: + if checkValue is None: return None if checkValue == "None": return None @@ -50,20 +50,20 @@ def checkInt(checkValue, defaultValue, allowNone=False): """Check if a variable is an integer or a none. """ if allowNone: - if checkValue == None: + if checkValue is None: return None if checkValue == "None": return None try: return int(checkValue) - except: + except Exception: return defaultValue def checkBool(checkValue, defaultValue, allowNone=False): """Check if a variable is a boolean or a none. """ if allowNone: - if checkValue == None: + if checkValue is None: return None if checkValue == "None": return None diff --git a/nw/config.py b/nw/config.py index f31a0d9e..96c5a71b 100644 --- a/nw/config.py +++ b/nw/config.py @@ -862,7 +862,7 @@ class Config: for i in range(listLen): try: outData.append(castTo(inData[i])) - except: + except Exception: outData.append(listDefault[i]) return outData @@ -905,13 +905,13 @@ class Config: import enchant self.hasEnchant = True logger.debug("Checking package 'pyenchant': Ok") - except: + except Exception: self.hasEnchant = False logger.debug("Checking package 'pyenchant': Missing") try: self.hasAssistant = which("assistant") - except: + except Exception: self.hasAssistant = False if self.hasAssistant: logger.debug("Checking executable 'assistant': Ok") diff --git a/nw/core/index.py b/nw/core/index.py index b111e9b1..b793ecc2 100644 --- a/nw/core/index.py +++ b/nw/core/index.py @@ -222,7 +222,7 @@ class NWIndex(): if len(self.textCounts[tHandle]) != 3: self.indexBroken = True - except: + except Exception: self.indexBroken = True if self.indexBroken: diff --git a/nw/core/item.py b/nw/core/item.py index 834164fd..09f3571b 100644 --- a/nw/core/item.py +++ b/nw/core/item.py @@ -130,7 +130,7 @@ class NWItem(): def _subPack(xParent, name, attrib=None, text=None, none=True): """Packs the values into an xml element. """ - if not none and (text == None or text == "None"): + if not none and (text is None or text == "None"): return None xSub = etree.SubElement(xParent, name, attrib=attrib) if text is not None: @@ -233,18 +233,18 @@ class NWItem(): """Save the expanded status of an item in the project tree. """ if isinstance(expState, str): - self.isExpanded = expState == str(True) + self.isExpanded = (expState == str(True)) else: - self.isExpanded = expState == True + self.isExpanded = (expState == True) # noqa return def setExported(self, expState): """Save the export flag. """ if isinstance(expState, str): - self.isExported = expState == str(True) + self.isExported = (expState == str(True)) else: - self.isExported = expState == True + self.isExported = (expState == True) # noqa return ## diff --git a/nw/core/options.py b/nw/core/options.py index a91f6f68..9a58bf7c 100644 --- a/nw/core/options.py +++ b/nw/core/options.py @@ -153,15 +153,15 @@ class OptionState(): def setValue(self, setGroup, setName, setValue): """Saves a value, with a given group and name. """ - if not setGroup in self.validMap: + if setGroup not in self.validMap: logger.error("Unknown option group '%s'" % setGroup) return False - if not setName in self.validMap[setGroup]: + if setName not in self.validMap[setGroup]: logger.error("Unknown option name '%s'" % setName) return False - if not setGroup in self.theState: + if setGroup not in self.theState: self.theState[setGroup] = {} self.theState[setGroup][setName] = setValue diff --git a/nw/core/project.py b/nw/core/project.py index b7f6596f..70ccc853 100644 --- a/nw/core/project.py +++ b/nw/core/project.py @@ -1243,7 +1243,8 @@ class NWProject(): for aValue in theValue: if not isinstance(aValue, str): aValue = str(aValue) - if aValue == "" and not allowNone: continue + if aValue == "" and not allowNone: + continue xItem = etree.SubElement(xParent, theName) xItem.text = aValue return @@ -1402,7 +1403,7 @@ class NWProject(): try: rmdir(theData) logger.info("Removed folder: %s" % theFolder) - except: + except Exception: errList.append("Failed to remove: %s" % theFolder) return errList diff --git a/nw/core/spellcheck.py b/nw/core/spellcheck.py index 50323cc0..296b1605 100644 --- a/nw/core/spellcheck.py +++ b/nw/core/spellcheck.py @@ -149,7 +149,7 @@ class NWSpellEnchant(NWSpellCheck): self.theDict = enchant.Dict(theLang) self.spellLanguage = theLang logger.debug("Enchant spell checking for language %s loaded" % theLang) - except: + except Exception: logger.error("Failed to load enchant spell checking for language %s" % theLang) self.theDict = NWSpellEnchantDummy() self.spellLanguage = None @@ -186,7 +186,7 @@ class NWSpellEnchant(NWSpellCheck): for spTag, spProvider in enchant.list_dicts(): spName = "%s [%s]" % (self.expandLanguage(spTag), spProvider.name) retList.append((spTag, spName)) - except: + except Exception: logger.error("Failed to list languages for enchant spell checking") return retList diff --git a/nw/core/tools.py b/nw/core/tools.py index 5ed4283e..80c1c867 100644 --- a/nw/core/tools.py +++ b/nw/core/tools.py @@ -78,7 +78,8 @@ def countWords(theText): charCount += theLen if countPara and prevEmpty: paraCount += 1 - prevEmpty = countPara == False + + prevEmpty = not countPara return charCount, wordCount, paraCount diff --git a/nw/gui/doceditor.py b/nw/gui/doceditor.py index 28624006..76fdc392 100644 --- a/nw/gui/doceditor.py +++ b/nw/gui/doceditor.py @@ -1272,7 +1272,7 @@ class GuiDocEditor(QTextEdit): try: isFind = self.lastFind[0] == theCursor.selectionStart() isFind &= self.lastFind[1] == theCursor.selectionEnd() - except: + except Exception: isFind = False if isFind: diff --git a/nw/gui/outline.py b/nw/gui/outline.py index c1986b98..1bc245b7 100644 --- a/nw/gui/outline.py +++ b/nw/gui/outline.py @@ -193,7 +193,7 @@ class GuiOutline(QTreeWidget): tHandle = tItem.data(self.colIndex[nwOutline.TITLE], Qt.UserRole) try: tLine = int(tItem.text(self.colIndex[nwOutline.LINE])) - except: + except Exception: tLine = 1 logger.verbose("User selected entry with handle %s on line %s" % (tHandle, tLine)) @@ -254,7 +254,7 @@ class GuiOutline(QTreeWidget): for hName in tempOrder: try: treeOrder.append(nwOutline[hName]) - except: + except Exception: logger.warning("Ignored unknown outline column '%s'" % str(hName)) # Add columns that was not in the file to the treeOrder array. @@ -276,14 +276,14 @@ class GuiOutline(QTreeWidget): for hName in tmpWidth: try: self.colWidth[nwOutline[hName]] = self.mainConf.pxInt(tmpWidth[hName]) - except: + except Exception: logger.warning("Ignored unknown outline column '%s'" % str(hName)) tmpHidden = self.optState.getValue("GuiOutline", "columnHidden", {}) for hName in tmpHidden: try: self.colHidden[nwOutline[hName]] = tmpHidden[hName] - except: + except Exception: logger.warning("Ignored unknown outline column '%s'" % str(hName)) self.headerMenu.setHiddenState(self.colHidden) diff --git a/nw/gui/outlinedetails.py b/nw/gui/outlinedetails.py index e18ac9d1..89aa7a3e 100644 --- a/nw/gui/outlinedetails.py +++ b/nw/gui/outlinedetails.py @@ -237,7 +237,7 @@ class GuiOutlineDetails(QScrollArea): nwItem = self.theProject.projTree[tHandle] novIdx = self.theIndex.novelIndex[tHandle][sTitle] theRefs = self.theIndex.getReferences(tHandle, sTitle) - except: + except Exception: return False if novIdx["level"] in self.LVL_MAP: diff --git a/nw/gui/projtree.py b/nw/gui/projtree.py index 253f21bb..77fd881a 100644 --- a/nw/gui/projtree.py +++ b/nw/gui/projtree.py @@ -756,7 +756,7 @@ class GuiProjectTree(QTreeWidget): if nHandle is not None and nHandle in self.theMap: try: byIndex = self.theMap[pHandle].indexOfChild(self.theMap[nHandle]) - except: + except Exception: logger.error("Failed to get index of item with handle %s" % nHandle) if byIndex >= 0: self.theMap[pHandle].insertChild(byIndex+1, newItem) diff --git a/nw/gui/statusbar.py b/nw/gui/statusbar.py index 19b4c44f..907937d4 100644 --- a/nw/gui/statusbar.py +++ b/nw/gui/statusbar.py @@ -242,9 +242,9 @@ class StatusLED(QAbstractButton): """ if theState is None: self._theCol = self.colNone - elif theState == True: + elif theState: self._theCol = self.colTrue - elif theState == False: + elif not theState: self._theCol = self.colFalse else: self._theCol = self.colNone diff --git a/nw/gui/theme.py b/nw/gui/theme.py index 685ab2b3..74642bef 100644 --- a/nw/gui/theme.py +++ b/nw/gui/theme.py @@ -182,7 +182,7 @@ class GuiTheme: for fontFam in listdir(fontAssets): fontDir = path.join(fontAssets, fontFam) if path.isdir(fontDir): - if not fontFam in self.guiFontDB.families(): + if fontFam not in self.guiFontDB.families(): for fontFile in listdir(fontDir): ttfFile = path.join(fontDir, fontFile) if path.isfile(ttfFile) and fontFile.endswith(".ttf"): @@ -438,7 +438,7 @@ class GuiTheme: outData.append(int(inData[0])) outData.append(int(inData[1])) outData.append(int(inData[2])) - except: + except Exception: logger.error("Could not load theme colours for '%s' from config file" % cnfName) outData = [0, 0, 0] else: @@ -456,7 +456,7 @@ class GuiTheme: readCol.append(int(inData[0])) readCol.append(int(inData[1])) readCol.append(int(inData[2])) - except: + except Exception: logger.error("Could not load theme colours for '%s' from config file" % cnfName) return if len(readCol) == 3: diff --git a/nw/guimain.py b/nw/guimain.py index 26f82518..33f42d8f 100644 --- a/nw/guimain.py +++ b/nw/guimain.py @@ -391,7 +391,7 @@ class GuiMain(QMainWindow): int(self.theProject.lockedBy[3]) ).strftime("%x %X") ) - except: + except Exception: lockDetails = "" msgBox = QMessageBox()