Skip to content

Commit 22d00dc

Browse files
committed
Apply changes to fix python linting errors
1 parent 4b71d79 commit 22d00dc

File tree

22 files changed

+58
-49
lines changed

22 files changed

+58
-49
lines changed

compiler/rustc_codegen_gcc/tools/generate_intrinsics.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import re
44
import sys
55
import subprocess
6-
from os import walk
76

87

98
def run_command(command, cwd=None):
@@ -180,7 +179,7 @@ def update_intrinsics(llvm_path, llvmint, llvmint2):
180179
intrinsics[arch].sort(key=lambda x: (x[0], x[2]))
181180
out.write(' // {}\n'.format(arch))
182181
for entry in intrinsics[arch]:
183-
if entry[2] == True: # if it is a duplicate
182+
if entry[2] is True: # if it is a duplicate
184183
out.write(' // [DUPLICATE]: "{}" => "{}",\n'.format(entry[0], entry[1]))
185184
elif "_round_mask" in entry[1]:
186185
out.write(' // [INVALID CONVERSION]: "{}" => "{}",\n'.format(entry[0], entry[1]))

library/core/src/unicode/printable.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def print_singletons(uppers, lowers, uppersname, lowersname):
119119
print("#[rustfmt::skip]")
120120
print("const {}: &[u8] = &[".format(lowersname))
121121
for i in range(0, len(lowers), 8):
122-
print(" {}".format(" ".join("{:#04x},".format(l) for l in lowers[i:i+8])))
122+
print(" {}".format(" ".join("{:#04x},".format(x) for x in lowers[i:i+8])))
123123
print("];")
124124

125125
def print_normal(normal, normalname):

src/bootstrap/bootstrap.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ def get_answer():
620620
# The latter one does not exist on NixOS when using tmpfs as root.
621621
try:
622622
with open("/etc/os-release", "r") as f:
623-
if not any(l.strip() in ("ID=nixos", "ID='nixos'", 'ID="nixos"') for l in f):
623+
if not any(ln.strip() in ("ID=nixos", "ID='nixos'", 'ID="nixos"') for ln in f):
624624
return False
625625
except FileNotFoundError:
626626
return False
@@ -872,7 +872,7 @@ def build_bootstrap(self, color, warnings, verbose_count):
872872
}
873873
for var_name, toml_key in var_data.items():
874874
toml_val = self.get_toml(toml_key, build_section)
875-
if toml_val != None:
875+
if toml_val is not None:
876876
env["{}_{}".format(var_name, host_triple_sanitized)] = toml_val
877877

878878
# preserve existing RUSTFLAGS

src/bootstrap/configure.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
rust_dir = os.path.dirname(rust_dir)
1010
rust_dir = os.path.dirname(rust_dir)
1111
sys.path.append(os.path.join(rust_dir, "src", "bootstrap"))
12-
import bootstrap
12+
import bootstrap # noqa: E402
1313

1414

1515
class Option(object):
@@ -319,7 +319,7 @@ def apply_args(known_args, option_checking, config):
319319
for key in known_args:
320320
# The `set` option is special and can be passed a bunch of times
321321
if key == 'set':
322-
for option, value in known_args[key]:
322+
for _option, value in known_args[key]:
323323
keyval = value.split('=', 1)
324324
if len(keyval) == 1 or keyval[1] == "true":
325325
value = True
@@ -401,7 +401,7 @@ def parse_example_config(known_args, config):
401401
top_level_keys = []
402402

403403
for line in open(rust_dir + '/config.example.toml').read().split("\n"):
404-
if cur_section == None:
404+
if cur_section is None:
405405
if line.count('=') == 1:
406406
top_level_key = line.split('=')[0]
407407
top_level_key = top_level_key.strip(' #')
@@ -523,8 +523,8 @@ def write_uncommented(target, f):
523523
block.append(line)
524524
if len(line) == 0:
525525
if not is_comment:
526-
for l in block:
527-
f.write(l + "\n")
526+
for ln in block:
527+
f.write(ln + "\n")
528528
block = []
529529
is_comment = True
530530
continue

src/ci/cpu-usage-over-time.py

100644100755
File mode changed.

src/ci/docker/host-x86_64/test-various/uefi_qemu_test/run.py

100644100755
File mode changed.

src/ci/docker/scripts/android-sdk-manager.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
# Simpler reimplementation of Android's sdkmanager
33
# Extra features of this implementation are pinning and mirroring
44

5+
import argparse
6+
import hashlib
7+
import os
8+
import subprocess
9+
import tempfile
10+
import urllib.request
11+
import xml.etree.ElementTree as ET
12+
513
# These URLs are the Google repositories containing the list of available
614
# packages and their versions. The list has been generated by listing the URLs
715
# fetched while executing `tools/bin/sdkmanager --list`
@@ -27,15 +35,6 @@
2735
MIRROR_BUCKET_REGION = "us-west-1"
2836
MIRROR_BASE_DIR = "rustc/android/"
2937

30-
import argparse
31-
import hashlib
32-
import os
33-
import subprocess
34-
import sys
35-
import tempfile
36-
import urllib.request
37-
import xml.etree.ElementTree as ET
38-
3938
class Package:
4039
def __init__(self, path, url, sha1, deps=None):
4140
if deps is None:

src/ci/docker/scripts/fuchsia-test-runner.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,8 +568,8 @@ def log(msg):
568568
env_vars += f'\n "{var_name}={var_value}",'
569569

570570
# Default to no backtrace for test suite
571-
if os.getenv("RUST_BACKTRACE") == None:
572-
env_vars += f'\n "RUST_BACKTRACE=0",'
571+
if os.getenv("RUST_BACKTRACE") is None:
572+
env_vars += '\n "RUST_BACKTRACE=0",'
573573

574574
cml.write(
575575
self.CML_TEMPLATE.format(env_vars=env_vars, exe_name=exe_name)

src/ci/stage-build.py

100644100755
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ def retry_action(action, name: str, max_fails: int = 5):
440440
try:
441441
action()
442442
return
443-
except:
443+
except BaseException: # also catch ctrl+c/sysexit
444444
LOGGER.error(f"Action `{name}` has failed\n{traceback.format_exc()}")
445445

446446
raise Exception(f"Action `{name}` has failed after {max_fails} attempts")
@@ -818,7 +818,7 @@ def extract_dist_dir(name: str) -> Path:
818818
# Extract rustc, libstd, cargo and src archives to create the optimized sysroot
819819
rustc_dir = extract_dist_dir(f"rustc-nightly-{PGO_HOST}") / "rustc"
820820
libstd_dir = extract_dist_dir(f"rust-std-nightly-{PGO_HOST}") / f"rust-std-{PGO_HOST}"
821-
cargo_dir = extract_dist_dir(f"cargo-nightly-{PGO_HOST}") / f"cargo"
821+
cargo_dir = extract_dist_dir(f"cargo-nightly-{PGO_HOST}") / "cargo"
822822
extracted_src_dir = extract_dist_dir("rust-src-nightly") / "rust-src"
823823

824824
# We need to manually copy libstd to the extracted rustc sysroot

src/etc/dec2flt_table.py

100644100755
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
available here: <https://github.com/fastfloat/fast_float/blob/main/script/table_generation.py>.
1515
"""
1616
from __future__ import print_function
17-
from math import ceil, floor, log, log2
18-
from fractions import Fraction
17+
from math import ceil, floor, log
1918
from collections import deque
2019

2120
HEADER = """
@@ -97,7 +96,6 @@ def print_proper_powers(min_exp, max_exp, bias):
9796
print('#[rustfmt::skip]')
9897
typ = '[(u64, u64); N_POWERS_OF_FIVE]'
9998
print('pub static POWER_OF_FIVE_128: {} = ['.format(typ))
100-
lo_mask = (1 << 64) - 1
10199
for c, exp in powers:
102100
hi = '0x{:x}'.format(c // (1 << 64))
103101
lo = '0x{:x}'.format(c % (1 << 64))

0 commit comments

Comments
 (0)