Skip to content

Commit ad177f9

Browse files
authored
mypyc: run pyupgrade (#12708)
Re-attempt of #10741 Ran: `pyupgrade --py36-plus $(fd -e py) --keep-runtime-typing` I mostly only needed to change things where NamedTuple comments got dropped.
1 parent 3c1a762 commit ad177f9

34 files changed

+406
-402
lines changed

mypyc/analysis/dataflow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def __init__(self, before: 'AnalysisDict[T]', after: 'AnalysisDict[T]') -> None:
125125
self.after = after
126126

127127
def __str__(self) -> str:
128-
return 'before: %s\nafter: %s\n' % (self.before, self.after)
128+
return f'before: {self.before}\nafter: {self.after}\n'
129129

130130

131131
GenAndKill = Tuple[Set[Value], Set[Value]]

mypyc/analysis/ircheck.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from mypyc.ir.func_ir import FuncIR, FUNC_STATICMETHOD
1818

1919

20-
class FnError(object):
20+
class FnError:
2121
def __init__(self, source: Union[Op, BasicBlock], desc: str) -> None:
2222
self.source = source
2323
self.desc = desc
@@ -129,8 +129,7 @@ def check_op_sources_valid(fn: FuncIR) -> List[FnError]:
129129
return errors
130130

131131

132-
disjoint_types = set(
133-
[
132+
disjoint_types = {
134133
int_rprimitive.name,
135134
bytes_rprimitive.name,
136135
str_rprimitive.name,
@@ -139,8 +138,7 @@ def check_op_sources_valid(fn: FuncIR) -> List[FnError]:
139138
set_rprimitive.name,
140139
tuple_rprimitive.name,
141140
range_rprimitive.name,
142-
]
143-
)
141+
}
144142

145143

146144
def can_coerce_to(src: RType, dest: RType) -> bool:

mypyc/build.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def generate_c(sources: List[BuildSource],
200200

201201
t1 = time.time()
202202
if compiler_options.verbose:
203-
print("Parsed and typechecked in {:.3f}s".format(t1 - t0))
203+
print(f"Parsed and typechecked in {t1 - t0:.3f}s")
204204

205205
if not messages and result:
206206
errors = Errors()
@@ -212,7 +212,7 @@ def generate_c(sources: List[BuildSource],
212212

213213
t2 = time.time()
214214
if compiler_options.verbose:
215-
print("Compiled to C in {:.3f}s".format(t2 - t1))
215+
print(f"Compiled to C in {t2 - t1:.3f}s")
216216

217217
# ... you know, just in case.
218218
if options.junit_xml:
@@ -304,7 +304,7 @@ def write_file(path: str, contents: str) -> None:
304304
try:
305305
with open(path, 'rb') as f:
306306
old_contents: Optional[bytes] = f.read()
307-
except IOError:
307+
except OSError:
308308
old_contents = None
309309
if old_contents != encoded_contents:
310310
os.makedirs(os.path.dirname(path), exist_ok=True)
@@ -513,8 +513,8 @@ def mypycify(
513513
cflags: List[str] = []
514514
if compiler.compiler_type == 'unix':
515515
cflags += [
516-
'-O{}'.format(opt_level),
517-
'-g{}'.format(debug_level),
516+
f'-O{opt_level}',
517+
f'-g{debug_level}',
518518
'-Werror', '-Wno-unused-function', '-Wno-unused-label',
519519
'-Wno-unreachable-code', '-Wno-unused-variable',
520520
'-Wno-unused-command-line-argument', '-Wno-unknown-warning-option',
@@ -535,7 +535,7 @@ def mypycify(
535535
elif debug_level in ('2', '3'):
536536
debug_level = "FULL"
537537
cflags += [
538-
'/O{}'.format(opt_level),
538+
f'/O{opt_level}',
539539
f'/DEBUG:{debug_level}',
540540
'/wd4102', # unreferenced label
541541
'/wd4101', # unreferenced local variable

mypyc/codegen/cstring.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from typing_extensions import Final
2424

2525

26-
CHAR_MAP: Final = ["\\{:03o}".format(i) for i in range(256)]
26+
CHAR_MAP: Final = [f"\\{i:03o}" for i in range(256)]
2727

2828
# It is safe to use string.printable as it always uses the C locale.
2929
for c in string.printable:
@@ -32,7 +32,7 @@
3232
# These assignments must come last because we prioritize simple escape
3333
# sequences over any other representation.
3434
for c in ('\'', '"', '\\', 'a', 'b', 'f', 'n', 'r', 't', 'v'):
35-
escaped = '\\{}'.format(c)
35+
escaped = f'\\{c}'
3636
decoded = escaped.encode('ascii').decode('unicode_escape')
3737
CHAR_MAP[ord(decoded)] = escaped
3838

0 commit comments

Comments
 (0)