Skip to content

Commit

Permalink
mypyc: run pyupgrade (#12708)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hauntsaninja authored May 1, 2022
1 parent 3c1a762 commit ad177f9
Show file tree
Hide file tree
Showing 34 changed files with 406 additions and 402 deletions.
2 changes: 1 addition & 1 deletion mypyc/analysis/dataflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def __init__(self, before: 'AnalysisDict[T]', after: 'AnalysisDict[T]') -> None:
self.after = after

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


GenAndKill = Tuple[Set[Value], Set[Value]]
Expand Down
8 changes: 3 additions & 5 deletions mypyc/analysis/ircheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from mypyc.ir.func_ir import FuncIR, FUNC_STATICMETHOD


class FnError(object):
class FnError:
def __init__(self, source: Union[Op, BasicBlock], desc: str) -> None:
self.source = source
self.desc = desc
Expand Down Expand Up @@ -129,8 +129,7 @@ def check_op_sources_valid(fn: FuncIR) -> List[FnError]:
return errors


disjoint_types = set(
[
disjoint_types = {
int_rprimitive.name,
bytes_rprimitive.name,
str_rprimitive.name,
Expand All @@ -139,8 +138,7 @@ def check_op_sources_valid(fn: FuncIR) -> List[FnError]:
set_rprimitive.name,
tuple_rprimitive.name,
range_rprimitive.name,
]
)
}


def can_coerce_to(src: RType, dest: RType) -> bool:
Expand Down
12 changes: 6 additions & 6 deletions mypyc/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def generate_c(sources: List[BuildSource],

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

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

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

# ... you know, just in case.
if options.junit_xml:
Expand Down Expand Up @@ -304,7 +304,7 @@ def write_file(path: str, contents: str) -> None:
try:
with open(path, 'rb') as f:
old_contents: Optional[bytes] = f.read()
except IOError:
except OSError:
old_contents = None
if old_contents != encoded_contents:
os.makedirs(os.path.dirname(path), exist_ok=True)
Expand Down Expand Up @@ -513,8 +513,8 @@ def mypycify(
cflags: List[str] = []
if compiler.compiler_type == 'unix':
cflags += [
'-O{}'.format(opt_level),
'-g{}'.format(debug_level),
f'-O{opt_level}',
f'-g{debug_level}',
'-Werror', '-Wno-unused-function', '-Wno-unused-label',
'-Wno-unreachable-code', '-Wno-unused-variable',
'-Wno-unused-command-line-argument', '-Wno-unknown-warning-option',
Expand All @@ -535,7 +535,7 @@ def mypycify(
elif debug_level in ('2', '3'):
debug_level = "FULL"
cflags += [
'/O{}'.format(opt_level),
f'/O{opt_level}',
f'/DEBUG:{debug_level}',
'/wd4102', # unreferenced label
'/wd4101', # unreferenced local variable
Expand Down
4 changes: 2 additions & 2 deletions mypyc/codegen/cstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from typing_extensions import Final


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

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

Expand Down
Loading

0 comments on commit ad177f9

Please sign in to comment.