From 2c585544a12868d41773a5d388c029c211e2658f Mon Sep 17 00:00:00 2001 From: Saeed Rasooli Date: Sun, 18 Sep 2022 16:37:17 +0430 Subject: [PATCH] use f-string equal syntax added in Python 3.8 https://github.com/python/cpython/issues/80998 --- pyglossary/compression.py | 4 ++-- pyglossary/core.py | 2 +- pyglossary/entry.py | 6 +++--- pyglossary/entry_filters.py | 2 +- pyglossary/glossary.py | 12 ++++++------ pyglossary/glossary_info.py | 14 +++++++------- pyglossary/html_utils.py | 2 +- pyglossary/langs/writing_system.py | 2 +- pyglossary/plugin_prop.py | 8 +++----- pyglossary/plugins/aard2_slob.py | 2 +- pyglossary/plugins/appledict/_content.py | 2 +- pyglossary/plugins/appledict_bin.py | 5 ++--- pyglossary/plugins/cc_cedict/conv.py | 2 +- pyglossary/plugins/cc_kedict.py | 2 +- pyglossary/plugins/dicformids.py | 4 ++-- pyglossary/plugins/dict_org.py | 2 +- pyglossary/plugins/freedict.py | 4 ++-- pyglossary/plugins/html_dir.py | 4 ++-- pyglossary/plugins/iupac_goldbook.py | 8 ++++---- pyglossary/plugins/octopus_mdict_new/__init__.py | 2 +- pyglossary/plugins/stardict.py | 14 +++++++------- pyglossary/plugins/xdxf/__init__.py | 2 +- pyglossary/plugins/zimfile.py | 4 ++-- pyglossary/reverse.py | 2 +- pyglossary/sq_entry_list.py | 10 +++++----- pyglossary/text_writer.py | 2 +- pyglossary/ui/base.py | 2 +- pyglossary/ui/main.py | 2 +- pyglossary/ui/ui_cmd_interactive.py | 4 ++-- pyglossary/ui/ui_gtk.py | 4 ++-- pyglossary/ui/ui_tk.py | 2 +- scripts/glos-find-bar-words.py | 2 +- scripts/plugin-doc.py | 4 ++-- tests/entry_test.py | 8 ++++---- tests/g_stardict_test.py | 2 +- tests/glossary_errors_test.py | 4 ++-- tests/glossary_test.py | 6 +++--- tests/gregorian_test.py | 6 +++--- tests/option_test.py | 2 +- 39 files changed, 84 insertions(+), 87 deletions(-) diff --git a/pyglossary/compression.py b/pyglossary/compression.py index e336bbfe8..64342b2f0 100644 --- a/pyglossary/compression.py +++ b/pyglossary/compression.py @@ -114,7 +114,7 @@ def compress(glos: "GlossaryType", filename: str, compression: str) -> str: f"{e}\nFailed to compress file \"{filename}\"" ) else: - raise ValueError(f"unexpected compression={compression!r}") + raise ValueError(f"unexpected {compression=}") if isfile(compFilename): return compFilename @@ -137,4 +137,4 @@ def uncompress(srcFilename: str, dstFilename: str, compression: str) -> None: return # TODO: if compression == "zip": - raise ValueError(f"unexpected compression={compression!r}") + raise ValueError(f"unexpected {compression=}") diff --git a/pyglossary/core.py b/pyglossary/core.py index e4f90c357..44d4bc0ff 100644 --- a/pyglossary/core.py +++ b/pyglossary/core.py @@ -316,7 +316,7 @@ def windows_show_exception(*exc_info): if getattr(sys, "frozen", False): # PyInstaller frozen executable - log.info(f"sys.frozen = {sys.frozen}") + log.info(f"{sys.frozen = }") rootDir = dirname(sys.executable) uiDir = join(rootDir, "pyglossary", "ui") else: diff --git a/pyglossary/entry.py b/pyglossary/entry.py index 04f090cb4..3a2195789 100644 --- a/pyglossary/entry.py +++ b/pyglossary/entry.py @@ -396,17 +396,17 @@ def stripFullHtml(self) -> None: word = self.s_word i = defi.find('') if i == -1: - log.error(f"'>' after ' after "Optional[BaseEntry]": word = entry.s_word if len(word) > 30: word = word[:37] + "..." - log.trace(f"MaxMemUsage: {usage}, word={word}") + log.trace(f"MaxMemUsage: {usage}, {word=}") return entry diff --git a/pyglossary/glossary.py b/pyglossary/glossary.py index a11a73ff0..3b0d47412 100644 --- a/pyglossary/glossary.py +++ b/pyglossary/glossary.py @@ -705,7 +705,7 @@ def sortWords( namedSortKey = namedSortKeyByName.get(sortKeyName) if namedSortKey is None: - log.critical(f"invalid sortKeyName = {sortKeyName!r}") + log.critical(f"invalid {sortKeyName = }") return if not sortEncoding: @@ -946,7 +946,7 @@ def _resolveConvertSortParams( sort = False if direct and sqlite: - raise ValueError(f"Conflictng arguments: direct={direct}, sqlite={sqlite}") + raise ValueError(f"Conflictng arguments: {direct=}, {sqlite=}") if not sort: if direct is None: @@ -990,7 +990,7 @@ def _resolveConvertSortParams( namedSortKey = namedSortKeyByName.get(sortKeyName) if namedSortKey is None: - log.critical(f"invalid sortKeyName = {sortKeyName!r}") + log.critical(f"invalid {sortKeyName = }") return None log.info(f"Using sortKeyName = {namedSortKey.name!r}") @@ -1058,9 +1058,9 @@ def convert( return if readOptions: - log.info(f"readOptions = {readOptions}") + log.info(f"{readOptions = }") if writeOptions: - log.info(f"writeOptions = {writeOptions}") + log.info(f"{writeOptions = }") outputArgs = self.detectOutputFormat( filename=outputFilename, @@ -1147,7 +1147,7 @@ def progressInit(self, *args) -> None: def progress(self, pos: int, total: int, unit: str = "entries") -> None: if total == 0: - log.warning(f"pos={pos}, total={total}") + log.warning(f"{pos=}, {total=}") return self.ui.progress( min(pos + 1, total) / total, diff --git a/pyglossary/glossary_info.py b/pyglossary/glossary_info.py index ebd8de8a0..b634fdbd9 100644 --- a/pyglossary/glossary_info.py +++ b/pyglossary/glossary_info.py @@ -51,7 +51,7 @@ def iterInfo(self) -> "Iterator[Tuple[str, str]]": def getInfo(self, key: str) -> str: if not isinstance(key, str): - raise TypeError(f"invalid key={key!r}, must be str") + raise TypeError(f"invalid {key=}, must be str") return self._info.get( infoKeysAliasDict.get(key.lower(), key), "", @@ -66,7 +66,7 @@ def setInfo(self, key: str, value: "Optional[str]") -> None: return if not isinstance(key, str): - raise TypeError(f"invalid key={key!r}, must be str") + raise TypeError(f"invalid {key=}, must be str") key = fixUtf8(key) value = fixUtf8(str(value)) @@ -127,13 +127,13 @@ def targetLang(self) -> "Optional[Lang]": @sourceLang.setter def sourceLang(self, lang) -> None: if not isinstance(lang, Lang): - raise TypeError(f"invalid lang={lang}, must be a Lang object") + raise TypeError(f"invalid {lang=}, must be a Lang object") self._info[c_sourceLang] = lang.name @targetLang.setter def targetLang(self, lang) -> None: if not isinstance(lang, Lang): - raise TypeError(f"invalid lang={lang}, must be a Lang object") + raise TypeError(f"invalid {lang=}, must be a Lang object") self._info[c_targetLang] = lang.name @property @@ -196,14 +196,14 @@ def detectLangsFromName(self): def checkPart(part: str): for match in re.findall("\w\w\w*", part): - # print(f"match = {match!r}") + # print(f"{match = }") lang = langDict[match] if lang is None: continue langNames.append(lang.name) for part in re.split("-| to ", name): - # print(f"part = {part!r}") + # print(f"{part = }") checkPart(part) if len(langNames) >= 2: break @@ -216,7 +216,7 @@ def checkPart(part: str): return if len(langNames) > 2: - log.warning(f"detectLangsFromName: langNames = {langNames!r}") + log.warning(f"detectLangsFromName: {langNames = }") log.info( f"Detected sourceLang={langNames[0]!r}, " diff --git a/pyglossary/html_utils.py b/pyglossary/html_utils.py index 319179caa..7f6cdf6d8 100644 --- a/pyglossary/html_utils.py +++ b/pyglossary/html_utils.py @@ -328,7 +328,7 @@ def build_name2codepoint_dict(): for key in sorted(name2str.keys(), key=lambda s: (s.lower(), s)): value = name2str[key] if len(value) > 1: - raise ValueError(f"value = {value!r}") + raise ValueError(f"{value = }") print(f"\t\"{key}\": 0x{ord(value):0>4x}, # {value}") diff --git a/pyglossary/langs/writing_system.py b/pyglossary/langs/writing_system.py index 09672c3c0..5ebad5e05 100644 --- a/pyglossary/langs/writing_system.py +++ b/pyglossary/langs/writing_system.py @@ -410,7 +410,7 @@ def _getWritingSystemFromText(st: str, start: int, end: int): unicodeWords = unicodedata.name(c).split(' ') except ValueError as e: # if c not in string.whitespace: - # print(f"c={c!r}, {e}") + # print(f"{c=}, {e}") continue alias = unicodeWords[0] ws = writingSystemByUnicode.get(alias) diff --git a/pyglossary/plugin_prop.py b/pyglossary/plugin_prop.py index 0230f4bfd..1e8abd43a 100644 --- a/pyglossary/plugin_prop.py +++ b/pyglossary/plugin_prop.py @@ -36,7 +36,7 @@ def optionsPropFromDict(optionsPropDict): try: prop = optionFromDict(propDict) except Exception: - log.exception(f"name={name!r}, propDict={propDict}\n") + log.exception(f"{name=}, {propDict=}\n") continue props[name] = prop return props @@ -283,9 +283,7 @@ def getOptionsFromClass(self, rwclass): default = getattr(rwclass, attrName) if name not in optionsProp: if not callable(default): - log.warning( - f"format={self.name}, attrName={attrName}, type={type(default)}" - ) + log.warning(f"format={self.name}, {attrName=}, {type(default)=}") continue prop = optionsProp[name] if prop.disabled: @@ -442,5 +440,5 @@ def getExtraOptionsFromFunc(cls, func, format): if name not in ("filename", "dirname"): extraOptNames.append(name) if extraOptNames: - log.warning(f"{format}: extraOptNames = {extraOptNames}") + log.warning(f"{format}: {extraOptNames = }") return extraOptNames diff --git a/pyglossary/plugins/aard2_slob.py b/pyglossary/plugins/aard2_slob.py index e199258f4..374a76d29 100644 --- a/pyglossary/plugins/aard2_slob.py +++ b/pyglossary/plugins/aard2_slob.py @@ -171,7 +171,7 @@ def __iter__(self): ctype = blob.content_type.split(";")[0] if ctype not in (MIME_HTML, MIME_TEXT): - log.debug(f"{word!r}: content_type={blob.content_type}") + log.debug(f"unknown {blob.content_type=} in {word=}") if word.startswith("~/"): word = word[2:] yield self._glos.newDataEntry(word, blob.content) diff --git a/pyglossary/plugins/appledict/_content.py b/pyglossary/plugins/appledict/_content.py index ec771bbbe..fda32dcb3 100644 --- a/pyglossary/plugins/appledict/_content.py +++ b/pyglossary/plugins/appledict/_content.py @@ -158,7 +158,7 @@ def prepare_content_with_soup( elif href.startswith(("phonetics", "help:phonetics")): # for oxford9 - log.debug(f"phonetics: tag={tag}") + log.debug(f"phonetics: {tag=}") if tag.audio and "name" in tag.audio.attrs: tag["onmousedown"] = f"this.lastChild.play(); return false;" src_name = tag.audio["name"].replace("#", "_") diff --git a/pyglossary/plugins/appledict_bin.py b/pyglossary/plugins/appledict_bin.py index 8396c2aed..8b9a2bc9a 100644 --- a/pyglossary/plugins/appledict_bin.py +++ b/pyglossary/plugins/appledict_bin.py @@ -230,8 +230,7 @@ def _readEntry(self, pos: int) -> "Tuple[BaseEntry, int]": entryRoot = etree.fromstring(entryFull) except etree.XMLSyntaxError as e: log.error( - f"pos={pos}, len(buf)={len(self._buf)}, " - f"entryFull={entryFull!r}" + f"{pos=}, len(buf)={len(self._buf)}, {entryFull=}" ) raise e entryElems = entryRoot.xpath("/d:entry", namespaces=entryRoot.nsmap) @@ -271,7 +270,7 @@ def readEntryIds(self): continue id_i = b_entry.find(b'id="') if id_i < 0: - log.error(f"id not found: {b_entry}, pos={pos}, buf={self._buf}") + log.error(f"id not found: {b_entry}, {pos=}, buf={self._buf}") continue id_j = b_entry.find(b'"', id_i + 4) if id_j < 0: diff --git a/pyglossary/plugins/cc_cedict/conv.py b/pyglossary/plugins/cc_cedict/conv.py index b1881a22e..8be8319fb 100644 --- a/pyglossary/plugins/cc_cedict/conv.py +++ b/pyglossary/plugins/cc_cedict/conv.py @@ -42,7 +42,7 @@ def make_entry(trad, simp, pinyin, eng, traditional_title): def colorize(hf, syllables, tones): if len(syllables) != len(tones): - log.warning(f"unmatched tones: syllables={syllables!r}, tones={tones}") + log.warning(f"unmatched tones: {syllables=}, {tones=}") with hf.element("div", style="display: inline-block"): for syllable in syllables: with hf.element("font", color=""): diff --git a/pyglossary/plugins/cc_kedict.py b/pyglossary/plugins/cc_kedict.py index 7515c0699..ff0ab5e81 100644 --- a/pyglossary/plugins/cc_kedict.py +++ b/pyglossary/plugins/cc_kedict.py @@ -164,7 +164,7 @@ def _processEntry( if self._spellKey and self._spellKey in edict: spelling = edict[self._spellKey] if not isinstance(spelling, str): - log.error(f"spelling = {spelling} type {type(spelling)}, edict={edict}") + log.error(f"{spelling=}, {type(spelling)=}, {edict=}") if spelling is True: # https://github.com/mhagiwara/cc-kedict/pull/1 spelling = "on" diff --git a/pyglossary/plugins/dicformids.py b/pyglossary/plugins/dicformids.py index dfe09f157..0416526ea 100644 --- a/pyglossary/plugins/dicformids.py +++ b/pyglossary/plugins/dicformids.py @@ -186,8 +186,8 @@ def write(self): def writeBucket(dicIndex: int, entryList: "List[BaseEntry]"): nonlocal dicMaxSize log.debug( - f"dicIndex={dicIndex}, len(entryList)={len(entryList)}" - f", dicMaxSize={dicMaxSize}" + f"{dicIndex=}, {len(entryList)=}" + f", {dicMaxSize=}" ) dicFp = open(join( self._dirname, diff --git a/pyglossary/plugins/dict_org.py b/pyglossary/plugins/dict_org.py index 59eed2cf0..4235711f7 100644 --- a/pyglossary/plugins/dict_org.py +++ b/pyglossary/plugins/dict_org.py @@ -120,7 +120,7 @@ def __iter__(self) -> "Iterator[BaseEntry]": defi = b_defi.decode("utf_8", 'ignore') defi = self.prettifyDefinitionText(defi) except Exception as e: - log.error(f"b_defi = {b_defi}") + log.error(f"{b_defi = }") raise e yield self._glos.newEntry(word, defi) diff --git a/pyglossary/plugins/freedict.py b/pyglossary/plugins/freedict.py index e30323435..ad7d35879 100644 --- a/pyglossary/plugins/freedict.py +++ b/pyglossary/plugins/freedict.py @@ -661,12 +661,12 @@ def setWordCount(self, header): return extent = extent_elem.text if not extent.endswith(" headwords"): - log.warning(f"unexpected extent={extent}") + log.warning(f"unexpected {extent=}") return try: self._wordCount = int(extent.split(" ")[0].replace(",", "")) except Exception: - log.exception(f"unexpected extent={extent}") + log.exception(f"unexpected {extent=}") def tostring(self, elem: "lxml.etree.Element") -> str: from lxml import etree as ET diff --git a/pyglossary/plugins/html_dir.py b/pyglossary/plugins/html_dir.py index 123f25a4e..d93ef0ec9 100644 --- a/pyglossary/plugins/html_dir.py +++ b/pyglossary/plugins/html_dir.py @@ -361,7 +361,7 @@ def navBar() -> str: tailSize = len(self._tail.encode(encoding)) if max_file_size < len(header) + tailSize: - raise ValueError(f"max_file_size={max_file_size} is too small") + raise ValueError(f"{max_file_size=} is too small") max_file_size -= tailSize @@ -421,7 +421,7 @@ def addLinks(text: str, pos: int) -> str: continue if entry.defi.startswith('') and defiFormat != "h": - log.error(f"bad defiFormat={defiFormat}") + log.error(f"bad {defiFormat=}") defiFormat = "h" entry.detectDefiFormat() diff --git a/pyglossary/plugins/iupac_goldbook.py b/pyglossary/plugins/iupac_goldbook.py index 43b3d3c22..f2894ebe0 100644 --- a/pyglossary/plugins/iupac_goldbook.py +++ b/pyglossary/plugins/iupac_goldbook.py @@ -148,7 +148,7 @@ def __iter__(self) -> "Iterator[BaseEntry]": _id = elem.attrib.get("id") termE = elem.find("./term") if termE is None: - log.warning(f"no term, code={code}, id={_id}") + log.warning(f"no term, {code=}, {_id=}") continue term = self.getTerm(termE) @@ -197,7 +197,7 @@ def __iter__(self) -> "Iterator[BaseEntry]": replacedbyCode = replacedby.split(".")[-1] replacedbyTerm = termByCode.get(replacedbyCode) if replacedbyTerm is None: - log.warning(f"{term}: replacedby={replacedby}") + log.warning(f"{term}: {replacedby=}") replacedbyTerm = replacedbyCode defiParts.append( f'Replaced by: {replacedbyTerm}' @@ -211,7 +211,7 @@ def __iter__(self) -> "Iterator[BaseEntry]": relatedCode = relatedURL.split("/")[-1] relatedTerm = termByCode.get(relatedCode) if not relatedTerm: - log.warning(f"{term}: related={relatedURL}") + log.warning(f"{term}: {relatedURL=}") relatedTerm = relatedCode relatedLinkList.append( f'{relatedTerm}' @@ -232,7 +232,7 @@ def __iter__(self) -> "Iterator[BaseEntry]": try: defi = "
".join(defiParts) except Exception: - log.error(f"defiParts = {defiParts!r}") + log.error(f"{defiParts = }") continue yield glos.newEntry( diff --git a/pyglossary/plugins/octopus_mdict_new/__init__.py b/pyglossary/plugins/octopus_mdict_new/__init__.py index a888d2906..d71ba5869 100644 --- a/pyglossary/plugins/octopus_mdict_new/__init__.py +++ b/pyglossary/plugins/octopus_mdict_new/__init__.py @@ -155,7 +155,7 @@ def loadLinks(self): "extracting links done, " f"sizeof(linksDict)={sys.getsizeof(linksDict)}" ) - log.info(f"wordCount = {wordCount}") + log.info(f"{wordCount = }") self._linksDict = linksDict self._wordCount = wordCount self._mdx = MDX(self._filename, self._encoding, self._substyle) diff --git a/pyglossary/plugins/stardict.py b/pyglossary/plugins/stardict.py index ba1b3cda6..289fd32a5 100644 --- a/pyglossary/plugins/stardict.py +++ b/pyglossary/plugins/stardict.py @@ -169,7 +169,7 @@ def open(self, filename: str) -> None: self.readIfoFile() sametypesequence = self._glos.getInfo("sametypesequence") if not verifySameTypeSequence(sametypesequence): - raise LookupError(f"Invalid sametypesequence = {sametypesequence}") + raise LookupError(f"Invalid {sametypesequence = }") self._indexData = self.readIdxFile() self._wordCount = len(self._indexData) self._synDict = self.readSynFile() @@ -321,7 +321,7 @@ def renderRawDefiList( return "\n".join(defis), _format if len(defiFormatSet) == 0: - log.error(f"empty defiFormatSet, rawDefiList={rawDefiList}") + log.error(f"empty defiFormatSet, {rawDefiList=}") return "", "" # convert plaintext or xdxf to html @@ -576,7 +576,7 @@ def finish(self) -> None: self._targetLang = None def open(self, filename: str) -> None: - log.debug(f"open: filename = {filename}") + log.debug(f"open: {filename = }") fileBasePath = filename ## if splitext(filename)[1].lower() == ".ifo": @@ -660,7 +660,7 @@ def writeCompact(self, defiFormat): Parameters: defiFormat - format of article definition: h - html, m - plain text """ - log.debug(f"writeCompact: defiFormat={defiFormat}") + log.debug(f"writeCompact: {defiFormat=}") dictMark = 0 altIndexList = [] # list of tuples (b"alternate", entryIndex) @@ -748,7 +748,7 @@ def writeGeneral(self) -> None: defiFormat = entry.defiFormat defiFormatCounter[defiFormat] += 1 if defiFormat not in ("h", "m", "x"): - log.error(f"invalid defiFormat={defiFormat}, using 'm'") + log.error(f"invalid {defiFormat=}, using 'm'") defiFormat = "m" words = entry.l_word # list of strs @@ -825,7 +825,7 @@ def writeCompactMergeSyns(self, defiFormat): Parameters: defiFormat - format of article definition: h - html, m - plain text """ - log.debug(f"writeCompactMergeSyns: defiFormat={defiFormat}") + log.debug(f"writeCompactMergeSyns: {defiFormat=}") dictMark = 0 idxBlockList = [] # list of tuples (b"word", startAndLength) altIndexList = [] # list of tuples (b"alternate", entryIndex) @@ -907,7 +907,7 @@ def writeGeneralMergeSyns(self) -> None: defiFormat = entry.defiFormat defiFormatCounter[defiFormat] += 1 if defiFormat not in ("h", "m", "x"): - log.error(f"invalid defiFormat={defiFormat}, using 'm'") + log.error(f"invalid {defiFormat=}, using 'm'") defiFormat = "m" words = entry.l_word # list of strs diff --git a/pyglossary/plugins/xdxf/__init__.py b/pyglossary/plugins/xdxf/__init__.py index e57cf649c..0e962ba74 100644 --- a/pyglossary/plugins/xdxf/__init__.py +++ b/pyglossary/plugins/xdxf/__init__.py @@ -154,7 +154,7 @@ def __iter__(self): defi = defi[4:-5].decode(self._encoding).strip() defiFormat = "x" - # log.info(f"defi={defi}, words={words}") + # log.info(f"{defi=}, {words=}") yield self._glos.newEntry( words, defi, diff --git a/pyglossary/plugins/zimfile.py b/pyglossary/plugins/zimfile.py index b68ea86bc..2e6169823 100644 --- a/pyglossary/plugins/zimfile.py +++ b/pyglossary/plugins/zimfile.py @@ -112,7 +112,7 @@ def __iter__(self): yield None # TODO: test with more zim files # Looks like: zItem.path == zEntry.path == "-" + word - # print(f"b_content empty, word={word!r}, zEntry.path={zEntry.path!r}, zItem.path={zItem.path}") + # print(f"b_content empty, {word=}, {zEntry.path=}, {zItem.path=}") # if zEntry.path == "-" + word: # yield None # else: @@ -141,7 +141,7 @@ def __iter__(self): continue if mimetype not in self.resourceMimeTypes: - log.warning(f"Unrecognized mimetype={mimetype!r}") + log.warning(f"Unrecognized {mimetype=}") if len(word) > f_namemax: fileNameTooLong.append(word) diff --git a/pyglossary/reverse.py b/pyglossary/reverse.py index a3031f5f5..1d14b8636 100644 --- a/pyglossary/reverse.py +++ b/pyglossary/reverse.py @@ -88,7 +88,7 @@ def reverseGlossary( defi = ", ".join(result) + "." except Exception: log.exception("") - log.debug(f"result = {result}") + log.debug(f"{result = }") return saveFile.write(f"{word}\t{defi}\n") yield wordI diff --git a/pyglossary/sq_entry_list.py b/pyglossary/sq_entry_list.py index 02dd64d28..4becf3f1e 100644 --- a/pyglossary/sq_entry_list.py +++ b/pyglossary/sq_entry_list.py @@ -59,7 +59,7 @@ def __init__( self._cur = self._con.cursor() if not filename: - raise ValueError(f"invalid filename={filename!r}") + raise ValueError(f"invalid {filename=}") self._orderBy = "rowid" self._sorted = False @@ -111,12 +111,12 @@ def append(self, entry): col[2](entry.l_word) for col in self._sqliteSortKey ] except Exception: - log.critical(f"error in _sqliteSortKey funcs for rawEntry = {rawEntry!r}") + log.critical(f"error in _sqliteSortKey funcs for {rawEntry = }") raise try: pickleEntry = dumps(rawEntry, protocol=PICKLE_PROTOCOL) except Exception: - log.critical(f"error in pickle.dumps for rawEntry = {rawEntry!r}") + log.critical(f"error in pickle.dumps for {rawEntry = }") raise self._cur.execute( f"insert into data({self._columnNames}, pickle)" @@ -158,11 +158,11 @@ def _parseExistingIndex(self) -> bool: # sql == "CREATE INDEX sortkey ON data(wordlower,word)" i = sql.find("(") if i < 0: - log.error(f"error parsing index sql={sql!r}") + log.error(f"error parsing index {sql=}") return False j = sql.find(")", i) if j < 0: - log.error(f"error parsing index sql={sql!r}") + log.error(f"error parsing index {sql=}") return False columnNames = sql[i + 1:j] self._sorted = True diff --git a/pyglossary/text_writer.py b/pyglossary/text_writer.py index 74e173fec..776ad0a60 100644 --- a/pyglossary/text_writer.py +++ b/pyglossary/text_writer.py @@ -112,7 +112,7 @@ def _open(self, filename: str): for key, value in self._glos.iterInfo(): # both key and value are supposed to be non-empty string if not (key and value): - log.warning(f"skipping info key={key!r}, value={value!r}") + log.warning(f"skipping info {key=}, {value=}") continue key = outInfoKeysAliasDict.get(key, key) if not key: diff --git a/pyglossary/ui/base.py b/pyglossary/ui/base.py index 09a47289a..b632dd985 100644 --- a/pyglossary/ui/base.py +++ b/pyglossary/ui/base.py @@ -66,7 +66,7 @@ def getEntryFilterConfigPair(name: str) -> "Tuple[str, Option]": elif isinstance(default, str): optClass = StrOption else: - raise TypeError(f"default = {default!r}") + raise TypeError(f"{default = }") return name, optClass( hasFlag=True, comment=filterClass.desc, diff --git a/pyglossary/ui/main.py b/pyglossary/ui/main.py index 75754b8f0..4676f15fb 100644 --- a/pyglossary/ui/main.py +++ b/pyglossary/ui/main.py @@ -730,7 +730,7 @@ def shouldUseCMD(args): writeOptions[optName] = optValueNew if convertOptions: - log.debug(f"convertOptions = {convertOptions}") + log.debug(f"{convertOptions = }") runKeywordArgs = dict( inputFilename=args.inputFilename, diff --git a/pyglossary/ui/ui_cmd_interactive.py b/pyglossary/ui/ui_cmd_interactive.py index e5aefda87..6325ed0fc 100644 --- a/pyglossary/ui/ui_cmd_interactive.py +++ b/pyglossary/ui/ui_cmd_interactive.py @@ -120,7 +120,7 @@ def space(event: "E") -> None: check.value = not check.value # cursor_pos = check.formatMessage().find("[") + 1 # cur_cursor_pos = session.default_buffer.cursor_position - # print(f"cur_cursor_pos={cur_cursor_pos}, cursor_pos={cursor_pos}") + # print(f"{cur_cursor_pos=}, {cursor_pos=}") # session.default_buffer.cursor_position = cursor_pos @bindings.add(Keys.Any) @@ -842,7 +842,7 @@ def setSortKey(self): return if sortKeyName not in namedSortKeyByName: - log.error(f"invalid sortKeyName = {sortKeyName!r}") + log.error(f"invalid {sortKeyName = }") return self._convertOptions["sortKeyName"] = sortKeyName diff --git a/pyglossary/ui/ui_gtk.py b/pyglossary/ui/ui_gtk.py index 92db7f430..76292acaa 100644 --- a/pyglossary/ui/ui_gtk.py +++ b/pyglossary/ui/ui_gtk.py @@ -631,7 +631,7 @@ def onChanged(self, obj=None): elif kind == "w": depends = plugin.writeDepends else: - raise RuntimeError(f"invalid kind={kind}") + raise RuntimeError(f"invalid {kind=}") uninstalled = checkDepends(depends) self.dependsButton.pkgNames = uninstalled @@ -1340,7 +1340,7 @@ def run( self.convertOptions = convertOptions if convertOptions: - log.debug(f"Using convertOptions={convertOptions}") + log.debug(f"Using {convertOptions=}") self._glossarySetAttrs = glossarySetAttrs diff --git a/pyglossary/ui/ui_tk.py b/pyglossary/ui/ui_tk.py index c655b8705..d68571258 100644 --- a/pyglossary/ui/ui_tk.py +++ b/pyglossary/ui/ui_tk.py @@ -1529,7 +1529,7 @@ def run( self._convertOptions = convertOptions if convertOptions: - log.info(f"Using convertOptions={convertOptions}") + log.info(f"Using {convertOptions=}") self._glossarySetAttrs = glossarySetAttrs diff --git a/scripts/glos-find-bar-words.py b/scripts/glos-find-bar-words.py index 525be3331..fe6be0f5d 100755 --- a/scripts/glos-find-bar-words.py +++ b/scripts/glos-find-bar-words.py @@ -21,7 +21,7 @@ def hasBar(entry): ) for direct in (True, False): - print(f"\n-------- direct={direct}") + print(f"\n-------- {direct=}") glos = Glossary() glos.config = { diff --git a/scripts/plugin-doc.py b/scripts/plugin-doc.py index cb83e9c3d..43aa57a31 100755 --- a/scripts/plugin-doc.py +++ b/scripts/plugin-doc.py @@ -240,7 +240,7 @@ def getToolSourceLink(tool): try: url, title = website except ValueError: - raise ValueError(f"website = {website!r}") + raise ValueError(f"{website = }") website_md = renderLink(title, url) ( @@ -294,7 +294,7 @@ def getToolSourceLink(tool): for optName, opt in optionsProp.items() } except Exception: - print(f"optionsProp = {optionsProp}") + print(f"{optionsProp = }") raise optionsComment = { optName: opt.comment.replace("\n", "
") diff --git a/tests/entry_test.py b/tests/entry_test.py index 8fa45df6f..b9103691a 100644 --- a/tests/entry_test.py +++ b/tests/entry_test.py @@ -153,7 +153,7 @@ def case( self.assertEqual(entry.defi, fixedDefi) if logMsg: record = self.mockLog.popLog(logLevel, logMsg) - self.assertIsNotNone(record, msg=f"logMsg={logMsg!r}") + self.assertIsNotNone(record, msg=f"{logMsg=}") def test_1(self): self.case( @@ -192,7 +192,7 @@ def test_5(self): word="test5", origDefi="simple html", fixedDefi="simple html", - logMsg="