misc,python: Run pre-commit run --all-files

Applies the `pyupgrade` hook to all files in the repo.

Change-Id: I9879c634a65c5fcaa9567c63bc5977ff97d5d3bf
This commit is contained in:
Bobby R. Bruce
2023-10-09 13:40:03 -07:00
parent 83af4525ce
commit 298119e402
188 changed files with 741 additions and 779 deletions

View File

@@ -46,7 +46,7 @@ import os
import re
class lookup(object):
class lookup:
def __init__(self, formatter, frame, *args, **kwargs):
self.frame = frame
self.formatter = formatter
@@ -106,7 +106,7 @@ class code_formatter_meta(type):
"""
def __init__(cls, name, bases, dct):
super(code_formatter_meta, cls).__init__(name, bases, dct)
super().__init__(name, bases, dct)
if "pattern" in dct:
pat = cls.pattern
else:
@@ -125,7 +125,7 @@ class code_formatter_meta(type):
cls.pattern = re.compile(pat, re.VERBOSE | re.DOTALL | re.MULTILINE)
class code_formatter(object, metaclass=code_formatter_meta):
class code_formatter(metaclass=code_formatter_meta):
delim = r"$"
ident = r"[_A-z]\w*"
pos = r"[0-9]+"
@@ -272,7 +272,7 @@ class code_formatter(object, metaclass=code_formatter_meta):
# check for a lone identifier
if ident:
indent = match.group("indent") # must be spaces
lone = "%s" % (l[ident],)
lone = f"{l[ident]}"
def indent_lines(gen):
for line in gen:
@@ -284,7 +284,7 @@ class code_formatter(object, metaclass=code_formatter_meta):
# check for an identifier, braced or not
ident = match.group("ident") or match.group("b_ident")
if ident is not None:
return "%s" % (l[ident],)
return f"{l[ident]}"
# check for a positional parameter, braced or not
pos = match.group("pos") or match.group("b_pos")
@@ -295,13 +295,13 @@ class code_formatter(object, metaclass=code_formatter_meta):
"Positional parameter #%d not found in pattern" % pos,
code_formatter.pattern,
)
return "%s" % (args[int(pos)],)
return f"{args[int(pos)]}"
# check for a double braced expression
eval_expr = match.group("eval")
if eval_expr is not None:
result = eval(eval_expr, {}, l)
return "%s" % (result,)
return f"{result}"
# check for an escaped delimiter
if match.group("escaped") is not None:

View File

@@ -66,7 +66,7 @@ code = code_formatter()
wrapper_name = enum.wrapper_name
wrapper = "struct" if enum.wrapper_is_struct else "namespace"
name = enum.__name__ if enum.enum_name is None else enum.enum_name
idem_macro = "__ENUM__%s__%s__" % (wrapper_name, name)
idem_macro = f"__ENUM__{wrapper_name}__{name}__"
code(
"""\

View File

@@ -36,7 +36,7 @@ class ParseError(Exception):
self.token = token
class Grammar(object):
class Grammar:
def setupLexerFactory(self, **kwargs):
if "module" in kwargs:
raise AttributeError("module is an illegal attribute")
@@ -92,7 +92,7 @@ class Grammar(object):
return self.current_lexer.lineno
raise AttributeError(
"'%s' object has no attribute '%s'" % (type(self), attr)
f"'{type(self)}' object has no attribute '{attr}'"
)
def parse_string(self, data, source="<string>", debug=None, tracking=0):
@@ -118,7 +118,7 @@ class Grammar(object):
def parse_file(self, f, **kwargs):
if isinstance(f, str):
source = f
f = open(f, "r")
f = open(f)
elif isinstance(f, file):
source = f.name
else:
@@ -137,7 +137,7 @@ class Grammar(object):
t.value,
)
else:
msg = "Syntax error at end of %s" % (self.current_source,)
msg = f"Syntax error at end of {self.current_source}"
raise ParseError(msg, t)
def t_error(self, t):

View File

@@ -56,7 +56,7 @@ for source in args.files:
# `README.md = "..."` which is not valid as `md` is not a property of
# `README`.
src = os.path.basename(source).replace(".", "_")
with open(source, "r") as f:
with open(source) as f:
data = "".join(f)
code("${src} = ${{repr(data)}}")

View File

@@ -74,7 +74,7 @@ if "LC_CTYPE" in os.environ:
_, cpp, python, modpath, abspath = sys.argv
with open(python, "r") as f:
with open(python) as f:
src = f.read()
compiled = compile(src, python, "exec")

View File

@@ -81,7 +81,7 @@ except:
warned_about_nested_templates = False
class CxxClass(object):
class CxxClass:
def __init__(self, sig, template_params=[]):
# Split the signature into its constituent parts. This could
# potentially be done with regular expressions, but