-
Notifications
You must be signed in to change notification settings - Fork 0
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
Sourcery refactored master branch #1
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.
Sourcery timed out performing refactorings.
Due to GitHub API limits, only the first 60 comments can be shown.
files = dict() | ||
deps: Dict[str, Set[str]] = dict() | ||
files = {} | ||
deps: Dict[str, Set[str]] = {} |
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 35-89
refactored with the following changes:
- Replace
dict()
with{}
[×3] (dict-literal
) - Use named expression to simplify assignment and conditional (
use-named-expression
) - Convert for loop into dictionary comprehension (
dict-comprehension
) - Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
) - Unwrap a constant iterable constructor (
unwrap-iterable-construction
) - Replace m.group(x) with m[x] for re.Match objects (
use-getitem-for-re-match-groups
)
This removes the following comments ( why? ):
# Build the transitive closure of dependencies of module
sys.exit('*** %s already has a copyright by The Bitcoin Core developers' | ||
% (filename)) | ||
sys.exit( | ||
f'*** {filename} already has a copyright by The Bitcoin Core developers' | ||
) |
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 exec_insert_header
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
sys.exit("*** bad filename: %s" % filename) | ||
sys.exit(f"*** bad filename: {filename}") | ||
_, extension = os.path.splitext(filename) | ||
if extension not in ['.h', '.cpp', '.cc', '.c', '.py', '.sh']: | ||
sys.exit("*** cannot insert for file extension %s" % extension) | ||
sys.exit(f"*** cannot insert for file extension {extension}") |
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 insert_cmd
refactored with the following changes:
- Replace interpolated string formatting with f-string [×2] (
replace-interpolation-with-fstring
) - Simplify conditional into switch-like form [×2] (
switch
)
outname = os.path.join(mandir, os.path.basename(abspath) + '.1') | ||
outname = os.path.join(mandir, f'{os.path.basename(abspath)}.1') | ||
print(f'Generating {outname}…') | ||
subprocess.run([help2man, '-N', '--version-string=' + verstr, '--include=' + footer.name, '-o', outname, abspath], check=True) | ||
subprocess.run( | ||
[ | ||
help2man, | ||
'-N', | ||
f'--version-string={verstr}', | ||
f'--include={footer.name}', | ||
'-o', | ||
outname, | ||
abspath, | ||
], | ||
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.
Lines 69-71
refactored with the following changes:
- Use f-string instead of string concatenation [×3] (
use-fstring-for-concatenation
)
have_gnu_relro = False | ||
for segment in binary.segments: | ||
# Note: not checking p_flags == PF_R: here as linkers set the permission differently | ||
# This does not affect security: the permission flags of the GNU_RELRO program | ||
# header are ignored, the PT_LOAD header determines the effective permissions. | ||
# However, the dynamic linker need to write to this area so these are RW. | ||
# Glibc itself takes care of mprotecting this area R after relocations are finished. | ||
# See also https://marc.info/?l=binutils&m=1498883354122353 | ||
if segment.type == lief.ELF.SEGMENT_TYPES.GNU_RELRO: | ||
have_gnu_relro = True | ||
|
||
have_gnu_relro = any( | ||
segment.type == lief.ELF.SEGMENT_TYPES.GNU_RELRO | ||
for segment in binary.segments | ||
) |
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_ELF_RELRO
refactored with the following changes:
- Use any() instead of for loop (
use-any
)
This removes the following comments ( why? ):
# This does not affect security: the permission flags of the GNU_RELRO program
# See also https://marc.info/?l=binutils&m=1498883354122353
# header are ignored, the PT_LOAD header determines the effective permissions.
# Note: not checking p_flags == PF_R: here as linkers set the permission differently
# However, the dynamic linker need to write to this area so these are RW.
# Glibc itself takes care of mprotecting this area R after relocations are finished.
if content.tolist() == [243, 15, 30, 250]: # endbr64 | ||
return True | ||
return False | ||
return content.tolist() == [243, 15, 30, 250] |
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_ELF_control_flow
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
) - Simplify boolean if expression (
boolean-if-exp-identity
) - Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast
)
This removes the following comments ( why? ):
# endbr64
Branch
master
refactored 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
master
branch, then run:Help us improve this pull request!