-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored master branch #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Due to GitHub API limits, only the first 60 comments can be shown.
| if class_first is not None: | ||
| if not name.endswith("Last>"): | ||
| raise ValueError("Missing Last after First") | ||
| if class_first is not None and not name.endswith("Last>"): | ||
| raise ValueError("Missing Last after First") | ||
|
|
||
| for c in range(prev_codepoint + 1, codepoint): | ||
| yield Codepoint(c, class_first) | ||
|
|
||
| class_first = None | ||
| if name.endswith("First>"): | ||
| class_first = class_ | ||
|
|
||
| class_first = class_ if name.endswith("First>") else None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function get_codepoints refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp) - Merge nested if conditions (
merge-nested-ifs) - Move setting of default value for variable into
elsebranch (introduce-default-else)
| if len(uppers) == 0 or uppers[-1][0] != upper: | ||
| if not uppers or uppers[-1][0] != upper: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function compress_singletons refactored with the following changes:
- Simplify sequence length comparison (
simplify-len-comparison)
| if falselen > 0x7f: | ||
| entry.append(0x80 | (falselen >> 8)) | ||
| entry.append(falselen & 0xff) | ||
| entry.extend((0x80 | (falselen >> 8), falselen & 0xff)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function compress_normal refactored with the following changes:
- Merge consecutive list appends into a single extend (
merge-list-appends-into-extend)
| print("const {}: &[(u8, u8)] = &[".format(uppersname)) | ||
| print(f"const {uppersname}: &[(u8, u8)] = &[") | ||
| for u, c in uppers: | ||
| print(" ({:#04x}, {}),".format(u, c)) | ||
| print("];") | ||
| print("#[rustfmt::skip]") | ||
| print("const {}: &[u8] = &[".format(lowersname)) | ||
| print(f"const {lowersname}: &[u8] = &[") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function print_singletons refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting)
| print("const {}: &[u8] = &[".format(normalname)) | ||
| print(f"const {normalname}: &[u8] = &[") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function print_normal refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting)
| filename = "rust-std-{}-{}{}".format( | ||
| rustc_channel, self.build, tarball_suffix) | ||
| pattern = "rust-std-{}".format(self.build) | ||
| filename = f"rust-std-{rustc_channel}-{self.build}{tarball_suffix}" | ||
| pattern = f"rust-std-{self.build}" | ||
| self._download_component_helper(filename, pattern, tarball_suffix, stage0) | ||
| filename = "rustc-{}-{}{}".format(rustc_channel, self.build, | ||
| tarball_suffix) | ||
| filename = f"rustc-{rustc_channel}-{self.build}{tarball_suffix}" | ||
| self._download_component_helper(filename, "rustc", tarball_suffix, stage0) | ||
| # download-rustc doesn't need its own cargo, it can just use beta's. | ||
| if stage0: | ||
| filename = "cargo-{}-{}{}".format(rustc_channel, self.build, | ||
| tarball_suffix) | ||
| filename = f"cargo-{rustc_channel}-{self.build}{tarball_suffix}" | ||
| self._download_component_helper(filename, "cargo", tarball_suffix) | ||
| self.fix_bin_or_dylib("{}/bin/cargo".format(bin_root)) | ||
| self.fix_bin_or_dylib(f"{bin_root}/bin/cargo") | ||
| else: | ||
| filename = "rustc-dev-{}-{}{}".format(rustc_channel, self.build, tarball_suffix) | ||
| filename = f"rustc-dev-{rustc_channel}-{self.build}{tarball_suffix}" | ||
| self._download_component_helper( | ||
| filename, "rustc-dev", tarball_suffix, stage0 | ||
| ) | ||
|
|
||
| self.fix_bin_or_dylib("{}/bin/rustc".format(bin_root)) | ||
| self.fix_bin_or_dylib("{}/bin/rustdoc".format(bin_root)) | ||
| lib_dir = "{}/lib".format(bin_root) | ||
| self.fix_bin_or_dylib(f"{bin_root}/bin/rustc") | ||
| self.fix_bin_or_dylib(f"{bin_root}/bin/rustdoc") | ||
| lib_dir = f"{bin_root}/lib" | ||
| for lib in os.listdir(lib_dir): | ||
| if lib.endswith(".so"): | ||
| self.fix_bin_or_dylib(os.path.join(lib_dir, lib)) | ||
| with output(self.rustc_stamp(stage0)) as rust_stamp: | ||
| rust_stamp.write(key) | ||
|
|
||
| if self.rustfmt() and self.rustfmt().startswith(bin_root) and ( | ||
| not os.path.exists(self.rustfmt()) | ||
| or self.program_out_of_date( | ||
| self.rustfmt_stamp(), | ||
| "" if self.stage0_rustfmt is None else self.stage0_rustfmt.channel() | ||
| if ( | ||
| self.rustfmt() | ||
| and self.rustfmt().startswith(bin_root) | ||
| and ( | ||
| not os.path.exists(self.rustfmt()) | ||
| or self.program_out_of_date( | ||
| self.rustfmt_stamp(), | ||
| "" | ||
| if self.stage0_rustfmt is None | ||
| else self.stage0_rustfmt.channel(), | ||
| ) | ||
| ) | ||
| and self.stage0_rustfmt is not None | ||
| ): | ||
| if self.stage0_rustfmt is not None: | ||
| tarball_suffix = '.tar.xz' if support_xz() else '.tar.gz' | ||
| filename = "rustfmt-{}-{}{}".format( | ||
| self.stage0_rustfmt.version, self.build, tarball_suffix, | ||
| ) | ||
| self._download_component_helper( | ||
| filename, "rustfmt-preview", tarball_suffix, key=self.stage0_rustfmt.date | ||
| ) | ||
| self.fix_bin_or_dylib("{}/bin/rustfmt".format(bin_root)) | ||
| self.fix_bin_or_dylib("{}/bin/cargo-fmt".format(bin_root)) | ||
| with output(self.rustfmt_stamp()) as rustfmt_stamp: | ||
| rustfmt_stamp.write(self.stage0_rustfmt.channel()) | ||
| tarball_suffix = '.tar.xz' if support_xz() else '.tar.gz' | ||
| filename = f"rustfmt-{self.stage0_rustfmt.version}-{self.build}{tarball_suffix}" | ||
|
|
||
| self._download_component_helper( | ||
| filename, "rustfmt-preview", tarball_suffix, key=self.stage0_rustfmt.date | ||
| ) | ||
| self.fix_bin_or_dylib(f"{bin_root}/bin/rustfmt") | ||
| self.fix_bin_or_dylib(f"{bin_root}/bin/cargo-fmt") | ||
| with output(self.rustfmt_stamp()) as rustfmt_stamp: | ||
| rustfmt_stamp.write(self.stage0_rustfmt.channel()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function RustBuild.download_toolchain refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting) - Merge nested if conditions (
merge-nested-ifs)
This removes the following comments ( why? ):
# the LLVM shared object file is named `LLVM-12-rust-{version}-nightly`
| if stage0: | ||
| key = self.stage0_compiler.date | ||
| else: | ||
| key = self.rustc_commit | ||
| key = self.stage0_compiler.date if stage0 else self.rustc_commit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function RustBuild._download_component_helper refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp) - Replace call to format with f-string. (
use-fstring-for-formatting)
| cache_prefix = "llvm-{}-{}".format(llvm_sha, llvm_assertions) | ||
| cache_prefix = f"llvm-{llvm_sha}-{llvm_assertions}" | ||
| cache_dst = os.path.join(self.build_dir, "cache") | ||
| rustc_cache = os.path.join(cache_dst, cache_prefix) | ||
| if not os.path.exists(rustc_cache): | ||
| os.makedirs(rustc_cache) | ||
|
|
||
| base = "https://ci-artifacts.rust-lang.org" | ||
| url = "rustc-builds/{}".format(llvm_sha) | ||
| url = f"rustc-builds/{llvm_sha}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function RustBuild._download_ci_llvm refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting) - Move assignments closer to their usage (
move-assign) - Use f-string instead of string concatenation (
use-fstring-for-concatenation) - Replace assignment and augmented assignment with single assignment (
merge-assign-and-aug-assign)
| if not any(line.strip() == "ID=nixos" for line in f): | ||
| if all(line.strip() != "ID=nixos" for line in f): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function RustBuild.fix_bin_or_dylib refactored with the following changes:
- Invert any/all to simplify comparisons (
invert-any-all) - Replace call to format with f-string. (
use-fstring-for-formatting) - Simplify unnecessary nesting, casting and constant values in f-strings (
simplify-fstring-formatting)
| assert download_rustc == "true" or download_rustc == "if-unchanged", download_rustc | ||
| assert download_rustc in ["true", "if-unchanged"], download_rustc | ||
|
|
||
| # Handle running from a directory other than the top level | ||
| rev_parse = ["git", "rev-parse", "--show-toplevel"] | ||
| top_level = subprocess.check_output(rev_parse, universal_newlines=True).strip() | ||
| compiler = "{}/compiler/".format(top_level) | ||
| library = "{}/library/".format(top_level) | ||
| compiler = f"{top_level}/compiler/" | ||
| library = f"{top_level}/library/" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function RustBuild.maybe_download_ci_toolchain refactored with the following changes:
- Replace multiple comparisons of same variable with
inoperator (merge-comparisons) - Replace call to format with f-string. (
use-fstring-for-formatting)
2e872ec to
a3588a7
Compare
| if stage0: | ||
| subdir = "stage0" | ||
| else: | ||
| subdir = "ci-rustc" | ||
| subdir = "stage0" if stage0 else "ci-rustc" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function RustBuild.bin_root refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| cur_section = section_match.group(1) | ||
| cur_section = section_match[1] | ||
|
|
||
| match = re.match(r'^{}\s*=(.*)$'.format(key), line) | ||
| match = re.match(f'^{key}\\s*=(.*)$', line) | ||
| if match is not None: | ||
| value = match.group(1) | ||
| value = match[1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function RustBuild.get_toml refactored with the following changes:
- Replace m.group(x) with m[x] for re.Match objects (
use-getitem-for-re-match-groups) - Replace call to format with f-string. (
use-fstring-for-formatting)
| if self.stage0_rustfmt is None: | ||
| return None | ||
| return self.program_config('rustfmt') | ||
| return None if self.stage0_rustfmt is None else self.program_config('rustfmt') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function RustBuild.rustfmt refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else) - Replace if statement with if expression (
assign-if-exp)
| config = self.get_toml(program) | ||
| if config: | ||
| if config := self.get_toml(program): | ||
| return os.path.expanduser(config) | ||
| return os.path.join(self.bin_root(stage0), "bin", "{}{}".format( | ||
| program, self.exe_suffix())) | ||
| return os.path.join( | ||
| self.bin_root(stage0), "bin", f"{program}{self.exe_suffix()}" | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function RustBuild.program_config refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression) - Replace call to format with f-string. (
use-fstring-for-formatting)
| if sys.platform == 'win32': | ||
| return '.exe' | ||
| return '' | ||
| return '.exe' if sys.platform == 'win32' else '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function RustBuild.exe_suffix refactored with the following changes:
- Lift code into else after jump in control flow (
reintroduce-else) - Replace if statement with if expression (
assign-if-exp)
| if not line.startswith('#' + key + ' = '): | ||
| if not line.startswith(f'#{key} = '): | ||
| continue | ||
| found = True | ||
| lines[i] = "{} = {}".format(key, to_toml(value)) | ||
| lines[i] = f"{key} = {to_toml(value)}" | ||
| break | ||
| if not found: | ||
| # These are used by rpm, but aren't accepted by x.py. | ||
| # Give a warning that they're ignored, but not a hard error. | ||
| if key in ["infodir", "localstatedir"]: | ||
| print("warning: {} will be ignored".format(key)) | ||
| print(f"warning: {key} will be ignored") | ||
| else: | ||
| raise RuntimeError("failed to find config line for {}".format(key)) | ||
| raise RuntimeError(f"failed to find config line for {key}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function configure_section refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation) - Replace call to format with f-string. (
use-fstring-for-formatting) - Swap positions of nested conditionals (
swap-nested-ifs) - Hoist repeated code outside conditional statement (
hoist-statement-from-if)
This removes the following comments ( why? ):
# Give a warning that they're ignored, but not a hard error.
# These are used by rpm, but aren't accepted by x.py.
| raise RuntimeError("config key {} not in sections".format(section_key)) | ||
| raise RuntimeError(f"config key {section_key} not in sections") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 465-495 refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting) - Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| "hash mismatch for package " + self.path + ": " + | ||
| sha1 + " vs " + self.sha1 + " (known good)" | ||
| ( | ||
| ( | ||
| ( | ||
| (f"hash mismatch for package {self.path}: " + sha1) | ||
| + " vs " | ||
| ) | ||
| + self.sha1 | ||
| ) | ||
| + " (known good)" | ||
| ) | ||
| ) | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Package.download refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| return "<Package "+self.path+" at "+self.url+" (sha1="+self.sha1+")" | ||
| return f"<Package {self.path} at {self.url} (sha1={self.sha1})" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Package.__repr__ refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| for dep in dependencies: | ||
| deps.append(dep.attrib["path"]) | ||
|
|
||
| deps.extend(dep.attrib["path"] for dep in dependencies) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function fetch_repository refactored with the following changes:
- Replace a for append loop with list extend (
for-append-to-extend)
| raise NameError("package not found: " + name) | ||
| raise NameError(f"package not found: {name}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Lockfile.add refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| f.write(package.path + " " + package.url + " " + package.sha1 + "\n") | ||
| f.write(f'{package.path} {package.url} {package.sha1}' + "\n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Lockfile.save refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| subprocess.run([ | ||
| "aws", "s3", "mv", path, | ||
| "s3://" + MIRROR_BUCKET + "/" + MIRROR_BASE_DIR + package.url, | ||
| "--profile=" + args.awscli_profile, | ||
| ], check=True) | ||
| subprocess.run( | ||
| [ | ||
| "aws", | ||
| "s3", | ||
| "mv", | ||
| path, | ||
| f"s3://{MIRROR_BUCKET}/{MIRROR_BASE_DIR}{package.url}", | ||
| f"--profile={args.awscli_profile}", | ||
| ], | ||
| check=True, | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function cli_update_mirror refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| url = "https://" + MIRROR_BUCKET + ".s3-" + MIRROR_BUCKET_REGION + \ | ||
| ".amazonaws.com/" + MIRROR_BASE_DIR | ||
| url = ( | ||
| f"https://{MIRROR_BUCKET}.s3-{MIRROR_BUCKET_REGION}" | ||
| + ".amazonaws.com/" | ||
| ) + MIRROR_BASE_DIR | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function cli_install refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| check_generic_bound(bound) | ||
| args = ty["inner"]["args"] | ||
| if args: | ||
| if args := ty["inner"]["args"]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function check_type refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression)
| if borrow >= 0: | ||
| return "Ref(borrow={})".format(borrow) | ||
| else: | ||
| return "Ref(borrow_mut={})".format(-borrow) | ||
| return f"Ref(borrow={borrow})" if borrow >= 0 else f"Ref(borrow_mut={-borrow})" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function StdRefProvider.to_string refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp) - Replace call to format with f-string. (
use-fstring-for-formatting)
| return "RefCell(borrow={})".format(borrow) | ||
| return f"RefCell(borrow={borrow})" | ||
| else: | ||
| return "RefCell(borrow_mut={})".format(-borrow) | ||
| return f"RefCell(borrow_mut={-borrow})" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function StdRefCellProvider.to_string refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting)
| return "BTreeSet(size={})".format(self.valobj["map"]["length"]) | ||
| return f'BTreeSet(size={self.valobj["map"]["length"]})' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function StdBTreeSetProvider.to_string refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting)
| yield "[{}]".format(i), child | ||
| yield (f"[{i}]", child) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function StdBTreeSetProvider.children refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting)
| return "BTreeMap(size={})".format(self.valobj["length"]) | ||
| return f'BTreeMap(size={self.valobj["length"]})' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function StdBTreeMapProvider.to_string refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting)
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 0.12%.
Here are some functions in these files that still need a tune-up:
Legend and ExplanationThe emojis denote the absolute quality of the code:
The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request. Please see our documentation here for details on how these metrics are calculated. We are actively working on this report - lots more documentation and extra metrics to come! Help us improve this quality report! |
Branch
masterrefactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
masterbranch, then run:Help us improve this pull request!