From c05e0fe6b1efa5259f013829403252dfe16d5a6a Mon Sep 17 00:00:00 2001 From: facelessuser Date: Sat, 2 Sep 2023 07:04:47 -0600 Subject: [PATCH] Run pyupgrade --py38-plus --- pyspelling/__init__.py | 4 ++-- pyspelling/__main__.py | 4 ++-- pyspelling/__meta__.py | 14 +++++++------- pyspelling/filters/context.py | 8 ++++---- pyspelling/filters/cpp.py | 6 +++--- pyspelling/filters/html.py | 2 +- pyspelling/filters/odf.py | 2 +- pyspelling/filters/ooxml.py | 6 +++--- pyspelling/filters/python.py | 16 ++++++++-------- pyspelling/filters/stylesheets.py | 2 +- pyspelling/filters/text.py | 4 ++-- pyspelling/plugin.py | 4 ++-- pyspelling/util/__init__.py | 2 +- tests/util.py | 12 ++++++------ 14 files changed, 43 insertions(+), 43 deletions(-) diff --git a/pyspelling/__init__.py b/pyspelling/__init__.py index d34bfb2..0be704a 100644 --- a/pyspelling/__init__.py +++ b/pyspelling/__init__.py @@ -212,7 +212,7 @@ def _walk_src(self, targets, flags, limit, pipeline, expect_match): if not found_something and expect_match: raise RuntimeError( 'None of the source targets from the configuration match any files:\n{}'.format( - '\n'.join('- {}'.format(target) for target in targets) + '\n'.join(f'- {target}' for target in targets) ) ) @@ -658,7 +658,7 @@ def spellcheck(config_file, names=None, groups=None, binary='', checker='', sour else: raise ValueError('%s is not a valid spellchecker!' % checker) - spellchecker.log('Using %s to spellcheck %s' % (checker, task.get('name', '')), 1) + spellchecker.log('Using {} to spellcheck {}'.format(checker, task.get('name', '')), 1) for result in spellchecker.run_task(task, source_patterns=sources): spellchecker.log('Context: %s' % result.context, 2) yield result diff --git a/pyspelling/__main__.py b/pyspelling/__main__.py index 9a9f6c0..a94088b 100644 --- a/pyspelling/__main__.py +++ b/pyspelling/__main__.py @@ -65,10 +65,10 @@ def run(config, **kwargs): count += 1 if results.error: fail = True - print('ERROR: %s -- %s' % (results.context, results.error)) + print(f'ERROR: {results.context} -- {results.error}') elif results.words: fail = True - print('Misspelled words:\n<%s> %s' % (results.category, results.context)) + print(f'Misspelled words:\n<{results.category}> {results.context}') print('-' * 80) for word in results.words: print(word) diff --git a/pyspelling/__meta__.py b/pyspelling/__meta__.py index a8059cf..1cc0849 100644 --- a/pyspelling/__meta__.py +++ b/pyspelling/__meta__.py @@ -88,7 +88,7 @@ def __new__(cls, major, minor, micro, release="final", pre=0, post=0, dev=0): raise ValueError("All version parts except 'release' should be integers.") if release not in REL_MAP: - raise ValueError("'{}' is not a valid release type.".format(release)) + raise ValueError(f"'{release}' is not a valid release type.") # Ensure valid pre-release (we do not allow implicit pre-releases). if ".dev-candidate" < release < "final": @@ -140,15 +140,15 @@ def _get_canonical(self): # Assemble major, minor, micro version and append `pre`, `post`, or `dev` if needed.. if self.micro == 0: - ver = "{}.{}".format(self.major, self.minor) + ver = f"{self.major}.{self.minor}" else: - ver = "{}.{}.{}".format(self.major, self.minor, self.micro) + ver = f"{self.major}.{self.minor}.{self.micro}" if self._is_pre(): - ver += '{}{}'.format(REL_MAP[self.release], self.pre) + ver += f'{REL_MAP[self.release]}{self.pre}' if self._is_post(): - ver += ".post{}".format(self.post) + ver += f".post{self.post}" if self._is_dev(): - ver += ".dev{}".format(self.dev) + ver += f".dev{self.dev}" return ver @@ -159,7 +159,7 @@ def parse_version(ver): m = RE_VER.match(ver) if m is None: - raise ValueError("'{}' is not a valid version".format(ver)) + raise ValueError(f"'{ver}' is not a valid version") # Handle major, minor, micro major = int(m.group('major')) diff --git a/pyspelling/filters/context.py b/pyspelling/filters/context.py index c6802e6..ad8403b 100644 --- a/pyspelling/filters/context.py +++ b/pyspelling/filters/context.py @@ -33,15 +33,15 @@ def validate_options(self, k, v): if k == 'delimiters': for d in v: if not isinstance(d, (dict, OrderedDict)): - raise ValueError("{}: 'delimters' entries must be of dict type.".format(self.__class__.__name__)) + raise ValueError(f"{self.__class__.__name__}: 'delimters' entries must be of dict type.") for key, value in d.items(): if key not in ('open', 'close', 'content'): raise KeyError( - "{}: '{}' is not a valid key for a 'delimeters' entry.".format(self.__class__.__name__, key) + f"{self.__class__.__name__}: '{key}' is not a valid key for a 'delimeters' entry." ) if not isinstance(value, str): raise ValueError( - "{}: 'delimeters' '{}' key should have str values.".format(self.__class__.__name__, value) + f"{self.__class__.__name__}: 'delimeters' '{value}' key should have str values." ) def setup(self): @@ -63,7 +63,7 @@ def setup(self): ): group = util.random_name_gen() - pattern = r'%s(?P<%s>%s)(?:%s|\Z)' % ( + pattern = r'{}(?P<{}>{})(?:{}|\Z)'.format( delimiter['open'], group, delimiter.get('content', DEFAULT_CONTENT), diff --git a/pyspelling/filters/cpp.py b/pyspelling/filters/cpp.py index 7d7b92b..d1334fc 100644 --- a/pyspelling/filters/cpp.py +++ b/pyspelling/filters/cpp.py @@ -133,16 +133,16 @@ def validate_options(self, k, v): super().validate_options(k, v) if k == 'charset_size': if v not in (1, 2, 4): - raise ValueError("{}: '{}' is an unsupported charset size".format(self.__class__.__name__, v)) + raise ValueError(f"{self.__class__.__name__}: '{v}' is an unsupported charset size") elif k == 'wide_charset_size': if v not in (2, 4): - raise ValueError("{}: '{}' is an unsupported wide charset size".format(self.__class__.__name__, v)) + raise ValueError(f"{self.__class__.__name__}: '{v}' is an unsupported wide charset size") elif k in ('exec_charset', 'wide_exec_charset'): # See if parsing fails. self.get_encoding_name(v) elif k == 'string_types': if RE_VALID_STRING_TYPES.match(v) is None: - raise ValueError("{}: '{}' does not define valid string types".format(self.__class__.__name__, v)) + raise ValueError(f"{self.__class__.__name__}: '{v}' does not define valid string types") def eval_string_type(self, text, is_string=False): """Evaluate string type.""" diff --git a/pyspelling/filters/html.py b/pyspelling/filters/html.py index 9b5f590..500750e 100644 --- a/pyspelling/filters/html.py +++ b/pyspelling/filters/html.py @@ -57,7 +57,7 @@ def validate_options(self, k, v): super().validate_options(k, v) if k == 'mode' and v not in MODE: - raise ValueError("{}: '{}' is not a valid value for '{}'".format(self.__class__.__name, v, k)) + raise ValueError(f"{self.__class__.__name}: '{v}' is not a valid value for '{k}'") def setup(self): """Setup.""" diff --git a/pyspelling/filters/odf.py b/pyspelling/filters/odf.py index 5c3f05e..a22efa8 100644 --- a/pyspelling/filters/odf.py +++ b/pyspelling/filters/odf.py @@ -123,7 +123,7 @@ def extract_tag_metadata(self, el): if self.type == 'odp': if el.namespace and el.namespace == self.namespaces['draw'] and el.name == 'page-thumbnail': name = el.attrs.get('draw:page-number', '') - self.additional_context = 'slide{}:'.format(name) + self.additional_context = f'slide{name}:' super().extract_tag_metadata(el) def reset(self): diff --git a/pyspelling/filters/ooxml.py b/pyspelling/filters/ooxml.py index 1c8b6d3..8d5fac9 100644 --- a/pyspelling/filters/ooxml.py +++ b/pyspelling/filters/ooxml.py @@ -103,7 +103,7 @@ def determine_file_type(self, z): for o in soup.find_all('Override'): name = o.attrs.get('PartName') for k, v in MIMEMAP.items(): - if name.startswith('/{}/'.format(k)): + if name.startswith(f'/{k}/'): self.type = v break if self.type: @@ -132,9 +132,9 @@ def get_context(self, filename): """Get context.""" if self.type == 'pptx': - context = '{}: '.format(RE_SLIDE.search(filename).group(1)) + context = f'{RE_SLIDE.search(filename).group(1)}: ' elif self.type == 'docx': - context = '{}: '.format(RE_DOCS.match(filename).group(1)) + context = f'{RE_DOCS.match(filename).group(1)}: ' else: context = '' return context diff --git a/pyspelling/filters/python.py b/pyspelling/filters/python.py index d6abdbe..b74f541 100644 --- a/pyspelling/filters/python.py +++ b/pyspelling/filters/python.py @@ -127,7 +127,7 @@ def validate_options(self, k, v): super().validate_options(k, v) if k == 'string_types': if RE_VALID_STRING_TYPES.match(v) is None: - raise ValueError("{}: '{}' does not define valid string types".format(self.__class__.__name__, v)) + raise ValueError(f"{self.__class__.__name__}: '{v}' does not define valid string types") def header_check(self, content): """Special Python encoding check.""" @@ -289,9 +289,9 @@ def _filter(self, text, context, encoding): if parent != self.MODULE: prefix = '.' if parent == self.CLASS else ', ' if name == 'class': - stack.append(('%s%s' % (prefix, value), len(indent), self.CLASS)) + stack.append((f'{prefix}{value}', len(indent), self.CLASS)) elif name == 'def': - stack.append(('%s%s()' % (prefix, value), len(indent), self.FUNCTION)) + stack.append((f'{prefix}{value}()', len(indent), self.FUNCTION)) name = None elif FSTR_TOKENIZE and token_type == tokenize.FSTRING_START: dstr = not self.catch_same_level(stack, len(indent)) and (prev_token_type in PREV_DOC_TOKENS) @@ -312,9 +312,9 @@ def _filter(self, text, context, encoding): comments[-1][2] = line_num else: if len(stack) > 1: - loc = "%s(%s): %s" % (stack[0][0], line, ''.join([crumb[0] for crumb in stack[1:]])) + loc = "{}({}): {}".format(stack[0][0], line, ''.join([crumb[0] for crumb in stack[1:]])) else: - loc = "%s(%s)" % (stack[0][0], line) + loc = f"{stack[0][0]}({line})" comments.append([value[1:], loc, line_num]) if FSTR_TOKENIZE and token_type == tokenize.FSTRING_MIDDLE and fstring_stack[-1][0]: @@ -326,7 +326,7 @@ def _filter(self, text, context, encoding): docstrings=dstr ) if string: - loc = "%s(%s): %s" % (stack[0][0], line, ''.join([crumb[0] for crumb in stack[1:]])) + loc = "{}({}): {}".format(stack[0][0], line, ''.join([crumb[0] for crumb in stack[1:]])) strings.append(filters.SourceText(string, loc, 'utf-8', 'py-string')) if token_type == tokenize.STRING: @@ -340,7 +340,7 @@ def _filter(self, text, context, encoding): value = value.strip() string, _is_bytes = self.process_strings(value, docstrings=True) if string: - loc = "%s(%s): %s" % (stack[0][0], line, ''.join([crumb[0] for crumb in stack[1:]])) + loc = "{}({}): {}".format(stack[0][0], line, ''.join([crumb[0] for crumb in stack[1:]])) docstrings.append( filters.SourceText(string, loc, 'utf-8', 'py-docstring') ) @@ -348,7 +348,7 @@ def _filter(self, text, context, encoding): value = value.strip() string, _is_bytes = self.process_strings(value) if string: - loc = "%s(%s): %s" % (stack[0][0], line, ''.join([crumb[0] for crumb in stack[1:]])) + loc = "{}({}): {}".format(stack[0][0], line, ''.join([crumb[0] for crumb in stack[1:]])) strings.append(filters.SourceText(string, loc, 'utf-8', 'py-string')) if token_type == tokenize.INDENT: diff --git a/pyspelling/filters/stylesheets.py b/pyspelling/filters/stylesheets.py index 16b0e8b..323ae22 100644 --- a/pyspelling/filters/stylesheets.py +++ b/pyspelling/filters/stylesheets.py @@ -57,7 +57,7 @@ def validate_options(self, k, v): super().validate_options(k, v) if k == 'stylesheets' and v not in STYLESHEET_TYPE: - raise ValueError("{}: '{}' is not a valid value for '{}'".format(self.__class__.__name, v, k)) + raise ValueError(f"{self.__class__.__name}: '{v}' is not a valid value for '{k}'") def setup(self): """Setup.""" diff --git a/pyspelling/filters/text.py b/pyspelling/filters/text.py index a4b1e9c..ccc53c0 100644 --- a/pyspelling/filters/text.py +++ b/pyspelling/filters/text.py @@ -26,9 +26,9 @@ def validate_options(self, k, v): super().validate_options(k, v) if k == 'errors' and v.lower() not in ('strict', 'replace', 'ignore', 'backslashreplace'): - raise ValueError("{}: '{}' is not a valid value for '{}'".format(self.__class__.__name, v, k)) + raise ValueError(f"{self.__class__.__name}: '{v}' is not a valid value for '{k}'") if k == 'normalize' and v.upper() not in ('NFC', 'NFKC', 'NFD', 'NFKD'): - raise ValueError("{}: '{}' is not a valid value for '{}'".format(self.__class__.__name, v, k)) + raise ValueError(f"{self.__class__.__name}: '{v}' is not a valid value for '{k}'") def setup(self): """Setup.""" diff --git a/pyspelling/plugin.py b/pyspelling/plugin.py index e0c0c18..947f3c7 100644 --- a/pyspelling/plugin.py +++ b/pyspelling/plugin.py @@ -12,7 +12,7 @@ def __init__(self, options): self.config = self.get_default_config() if self.config is None: warnings.warn( - "'{}' did not provide a default config. ".format(self.__class__.__name__) + + f"'{self.__class__.__name__}' did not provide a default config. " + "All plugins in the future should provide a default config.", category=FutureWarning, stacklevel=1 @@ -36,7 +36,7 @@ def override_config(self, options): for k, v in options.items(): # Reject names not in the default configuration if k not in self.config: - raise KeyError("'{}' is not a valid option for '{}'".format(k, self.__class__.__name__)) + raise KeyError(f"'{k}' is not a valid option for '{self.__class__.__name__}'") self.validate_options(k, v) self.config[k] = v diff --git a/pyspelling/util/__init__.py b/pyspelling/util/__init__.py index a1fad30..0868054 100644 --- a/pyspelling/util/__init__.py +++ b/pyspelling/util/__init__.py @@ -29,7 +29,7 @@ def deprecated_func(*args, **kwargs): """Display deprecation warning.""" warnings.warn( - "'{}' is deprecated. {}".format(func.__name__, message), + f"'{func.__name__}' is deprecated. {message}", category=DeprecationWarning, stacklevel=2 ) diff --git a/tests/util.py b/tests/util.py index 6bfc06a..5808aa5 100644 --- a/tests/util.py +++ b/tests/util.py @@ -18,7 +18,7 @@ # Disambiguate `TESTFN` for parallel testing, while letting it remain a valid # module name. -TESTFN = "{}_{}_tmp".format(TESTFN, os.getpid()) +TESTFN = f"{TESTFN}_{os.getpid()}_tmp" def which(executable): @@ -121,13 +121,13 @@ def assert_spell_required(self, running): required = os.environ.get("TOX_SPELL_REQUIRE", "any") if required not in ("both", "any", "aspell", "hunspell"): - raise RuntimeError("Invalid value of '{}' in 'TOX_SPELL_REQUIRE'".format(required)) + raise RuntimeError(f"Invalid value of '{required}' in 'TOX_SPELL_REQUIRE'") if running not in ("both", "aspell", "hunspell"): raise RuntimeError( - "Required tests are not being run (currently running '{}'). ".format(running) + + f"Required tests are not being run (currently running '{running}'). " + "Make sure spell checker can be found and " + - "'TOX_SPELL_REQUIRE' is set appropriately (currently '{}')".format(required) + f"'TOX_SPELL_REQUIRE' is set appropriately (currently '{required}')" ) if required != running and (required != "any" and running != "both"): @@ -166,7 +166,7 @@ def assert_context(self, config_file, expected, names=None, groups=None, sources if results.error: print(results.error) context.append(results.context) - self.assertEqual([('{}/{}'.format(self.tempdir, i) if i else i) for i in expected[:]], context) + self.assertEqual([(f'{self.tempdir}/{i}' if i else i) for i in expected[:]], context) if aspell_location: context = [] for results in spellcheck( @@ -182,7 +182,7 @@ def assert_context(self, config_file, expected, names=None, groups=None, sources if results.error: print(results.error) context.append(results.context) - self.assertEqual([('{}/{}'.format(self.tempdir, i) if i else i) for i in expected[:]], context) + self.assertEqual([(f'{self.tempdir}/{i}' if i else i) for i in expected[:]], context) def assert_spellcheck(self, config_file, expected, names=None, groups=None, sources=None, verbose=4): """Spell check."""