-
Notifications
You must be signed in to change notification settings - Fork 13
Sourcery refactored development branch #12
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
Conversation
if n < 2: | ||
return 1 | ||
else: | ||
return n*fac(n-1) | ||
return 1 if n < 2 else n*fac(n-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 fac
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
if n == 0 or n == 1: | ||
return 1 | ||
else: | ||
return fib(n-1) + fib(n-2) | ||
return 1 if n in [0, 1] else fib(n-1) + fib(n-2) |
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 fib
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
) - Replace multiple comparisons of same variable with
in
operator (merge-comparisons
)
print('account: ' + options.account) | ||
print(f'account: {options.account}') |
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 22-22
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
args = list() | ||
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 parse_job_script
refactored with the following changes:
- Replace
list()
with[]
(list-literal
)
if name is None: | ||
if self.name is None: | ||
return 'No one to say hello to' | ||
else: | ||
return f'Hello to {self.name}' | ||
else: | ||
if name is not None: | ||
return f'Hello {name}' | ||
if self.name is None: | ||
return 'No one to say hello to' | ||
else: | ||
return f'Hello to {self.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 Hello.to
refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
)
data = dict() | ||
data['time'] = list() | ||
data = {'time': []} | ||
for var in meta_data: | ||
data[meta_data[var]] = list() | ||
data[meta_data[var]] = [] |
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 init_data
refactored with the following changes:
- Merge dictionary assignment with declaration (
merge-dict-assign
) - Replace
dict()
with{}
(dict-literal
) - Replace
list()
with[]
[×2] (list-literal
)
buffer = dict() | ||
buffer = {} |
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 parse_data
refactored with the following changes:
- Replace
dict()
with{}
(dict-literal
)
data_line = list() | ||
for var in columns: | ||
data_line.append(data[var][time_step]) | ||
data_line = [data[var][time_step] for var in columns] |
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 write_vcd_data_structure
refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension
) - Replace
list()
with[]
(list-literal
)
print("### checking directory '{}'".format(directory), | ||
file=sys.stderr) | ||
print(f"### checking directory '{directory}'", file=sys.stderr) |
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 19-20
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
person = { | ||
'id': ''.join(random.choices(string.ascii_letters, k=5)), | ||
return { | ||
'id': ''.join(random.choices(string.ascii_letters, k=5)), | ||
'birthyear': random.randint(1950, 2015), | ||
'nr_friends': random.randint(0, 50), | ||
} | ||
return person |
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 generate_person
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
template = environment.get_template('report.' + options.format) | ||
template = environment.get_template(f'report.{options.format}') |
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 main
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
if options.info: | ||
level = logging.INFO | ||
else: | ||
level = logging.WARNING | ||
if options.new_log: | ||
filemode = 'w' | ||
else: | ||
filemode = 'a' | ||
level = logging.INFO if options.info else logging.WARNING | ||
if options.log_file: | ||
log_file = Path(options.log_file) | ||
exists = log_file.exists() | ||
filemode = 'w' if options.new_log else 'a' |
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 main
refactored with the following changes:
- Replace if statement with if expression [×2] (
assign-if-exp
) - Move assignments closer to their usage (
move-assign
)
cmd += ' ' + options.dir | ||
cmd += f' {options.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.
Lines 27-27
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
for parent in reversed(parents): | ||
if parent.username() == username: | ||
return parent | ||
return process | ||
return next( | ||
( | ||
parent | ||
for parent in reversed(parents) | ||
if parent.username() == username | ||
), | ||
process, | ||
) |
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 find_ancestor
refactored with the following changes:
- Use the built-in function
next
instead of a for-loop (use-next
)
open_files = list() | ||
open_files = [] | ||
try: | ||
for file in process.open_files(): | ||
try: | ||
if 'r' == file.mode: | ||
if file.mode == 'r': |
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_read_open_files
refactored with the following changes:
- Replace
list()
with[]
(list-literal
) - Ensure constant in comparison is on the right (
flip-comparison
)
metrics = dict() | ||
metrics['time'] = Metric('time', lambda x: time.time()) | ||
metrics = {'time': Metric('time', lambda x: time.time())} |
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 define_actions
refactored with the following changes:
- Merge dictionary assignment with declaration (
merge-dict-assign
) - Replace
dict()
with{}
(dict-literal
)
status = list() | ||
status = [] | ||
with process.oneshot(): | ||
for metric in metrics.values(): | ||
if metric.is_active: | ||
status.append(metric.measure(process)) | ||
status.extend( | ||
metric.measure(process) | ||
for metric in metrics.values() | ||
if metric.is_active | ||
) |
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 process_status
refactored with the following changes:
- Replace
list()
with[]
(list-literal
) - Replace a for append loop with list extend (
for-append-to-extend
)
inactive.append('read_files') | ||
inactive.append('write_files') | ||
inactive.extend(('read_files', 'write_files')) | ||
metrics = define_actions(inactive) | ||
if options.output_file: | ||
file = open(options.output_file, 'w') | ||
else: | ||
file = sys.stdout | ||
file = open(options.output_file, 'w') if options.output_file else sys.stdout | ||
try: | ||
with file: | ||
print(status_header(metrics), file=file) | ||
while True: | ||
process_info = [process_status(process, metrics)] | ||
for child_process in process.children(recursive=True): | ||
process_info.append(process_status(child_process, metrics)) | ||
process_info.extend( | ||
process_status(child_process, metrics) | ||
for child_process in process.children(recursive=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 main
refactored with the following changes:
- Merge consecutive list appends into a single extend (
merge-list-appends-into-extend
) - Replace if statement with if expression (
assign-if-exp
) - Replace a for append loop with list extend (
for-append-to-extend
)
return_code = process.wait() | ||
if return_code: | ||
if return_code := process.wait(): |
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 execute
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
)
if node_list: | ||
parent = random.choice(node_list) | ||
else: | ||
parent = doc | ||
parent = random.choice(node_list) if node_list else doc |
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 Docs.random
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
Branch
development
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
development
branch, then run:Help us improve this pull request!