-
Notifications
You must be signed in to change notification settings - Fork 53
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 #407
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.
print("epoch:%s, iter:%s" % (i, j)) | ||
print(f"epoch:{i}, iter:{j}") |
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 train
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
center = data[0:2] | ||
center = data[: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 compute_segments
refactored with the following changes:
- Replace a[0:x] with a[:x] and a[x:len(a)] with a[x:] (
remove-redundant-slice-index
)
time_avg = float(match.group(1)) | ||
time_avg = float(match[1]) | ||
nr_timings += 1 | ||
continue | ||
match = re.match('^procs: (\d+)$', line) | ||
if match is not None: | ||
nr_procs = int(match.group(1)) | ||
nr_procs = int(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.
Lines 20-25
refactored with the following changes:
- Replace m.group(x) with m[x] for re.Match objects [×2] (
use-getitem-for-re-match-groups
)
if options.version == '3': | ||
version = 'NETCDF3_CLASSIC' | ||
else: | ||
version = 'NETCDF4' | ||
version = 'NETCDF3_CLASSIC' if options.version == '3' else 'NETCDF4' |
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 20-23
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
avail_nucls = available_nucl(nucl_left) | ||
if avail_nucls: | ||
if avail_nucls := available_nucl(nucl_left): |
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_nucl
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
)
if not rows: | ||
msg = "constant '{0}' is undefined".format(name) | ||
raise UnknownConstantError(msg) | ||
else: | ||
if rows: | ||
return rows[0][0] | ||
msg = "constant '{0}' is undefined".format(name) | ||
raise UnknownConstantError(msg) |
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 ConstantDb.get_value
refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
)
if n > 1: | ||
return n*fac(n - 1) | ||
else: | ||
return 1 | ||
return n*fac(n - 1) if n > 1 else 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
)
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 len(sys.argv) > 1: | ||
cfg_file = sys.argv[1] | ||
else: | ||
cfg_file = 'defaults.conf' | ||
cfg_file = sys.argv[1] if len(sys.argv) > 1 else 'defaults.conf' |
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 (
assign-if-exp
)
with ContextTest(1) as c1, ContextTest(2) as c2: | ||
with (ContextTest(1) as c1, ContextTest(2) as c2): | ||
print('in context {0}'.format(c1._context_nr)) | ||
raise Exception() | ||
print('in context {0}'.format(c2._context_nr)) |
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:
- Remove unreachable code (
remove-unreachable-code
)
if mode == float: | ||
return [float(item) for item in items] | ||
else: | ||
return items | ||
return [float(item) for item in items] if mode == float else items |
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_line
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
averagers = [stats() for name in names] | ||
averagers = [stats() for _ in names] |
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 37-37
refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore
)
for iter_nr in range(options.iter): | ||
for _ in range(options.iter): |
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 28-28
refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore
)
if kmax > 1000: | ||
kmax = 1000 | ||
kmax = min(kmax, 1000) | ||
k = 0 | ||
n = 2 | ||
while k < kmax: | ||
i = 0 | ||
while i < k and n % p[i] != 0: | ||
i = i + 1 | ||
i += 1 | ||
if i == k: | ||
p[k] = n | ||
k = k + 1 | ||
k += 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 primes
refactored with the following changes:
- Replace comparison with min/max call (
min-max-identity
) - Replace assignment with augmented assignment [×2] (
aug-assign
)
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
)
jobs = [] | ||
for name in names: | ||
jobs.append((random.random(), name)) | ||
return jobs | ||
return [(random.random(), name) for name in names] |
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 create_jobs
refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
)
if len(args) != 1 and len(args) != 3: | ||
if len(args) not in [1, 3]: |
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 ExperimentShell.parse_show_arg
refactored with the following changes:
- Replace multiple comparisons of same variable with
in
operator (merge-comparisons
)
else: | ||
if cls == Experiment: | ||
items = self._db_session.\ | ||
elif cls == Experiment: | ||
items = self._db_session.\ | ||
query(Experiment).\ | ||
join(staff_assignments).\ | ||
filter_by(researcher_id=item_id).all() | ||
elif cls == Researcher: | ||
items = self._db_session.\ | ||
elif cls == Researcher: | ||
items = self._db_session.\ | ||
query(Researcher).\ | ||
join(staff_assignments).\ | ||
filter_by(experiment_id=item_id).all() | ||
elif cls == Sample: | ||
items = self._db_session.\ | ||
elif cls == Sample: | ||
items = self._db_session.\ |
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 ExperimentShell.do_show
refactored with the following changes:
- Merge else clause's nested if statement into elif (
merge-else-if-into-elif
)
print('\t{}'.format(sample.description)) | ||
print(f'\t{sample.description}') |
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 20-29
refactored with the following changes:
- Replace call to format with f-string [×2] (
use-fstring-for-formatting
)
cities = [] | ||
for city_nr in range(nr_cities): | ||
cities.append(''.join([random.choice(string.letters) | ||
for i in range(code_length)])) | ||
return cities | ||
return [ | ||
''.join([random.choice(string.letters) for _ in range(code_length)]) | ||
for _ in range(nr_cities) | ||
] |
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_city_codes
refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension
) - Replace unused for index with underscore [×2] (
for-index-underscore
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
)
if n == 0: | ||
return 1 | ||
else: | ||
return n*fact(n - 1) | ||
return 1 if n == 0 else n*fact(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 fact
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
if n < 2: | ||
return 1 | ||
else: | ||
return fib_memoized(n - 1) + fib_memoized(n - 2) | ||
return 1 if n < 2 else fib_memoized(n - 1) + fib_memoized(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_memoized
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
if coord[0] - 1 >= 0: | ||
if coord[0] >= 1: | ||
neighbours.append((coord[0] - 1, coord[1])) | ||
if coord[0] + 1 < size: | ||
neighbours.append((coord[0] + 1, coord[1])) | ||
if coord[1] - 1 >= 0: | ||
if coord[1] >= 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 compute_neighbouts
refactored with the following changes:
- Simplify numeric comparison [×2] (
simplify-numeric-comparison
)
while len(queue) > 0: | ||
while queue: |
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_domain
refactored with the following changes:
- Simplify sequence length comparison (
simplify-len-comparison
)
domains = [] | ||
for _ in range(len(lattice)): | ||
domains.append([-1] * len(lattice)) | ||
domains = [[-1] * len(lattice) for _ in range(len(lattice))] |
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 identify_domains
refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension
)
if len(sys.argv) > 1: | ||
n = int(sys.argv[1]) | ||
else: | ||
n = 10 | ||
n = int(sys.argv[1]) if len(sys.argv) > 1 else 10 |
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 (
assign-if-exp
)
if n == 1 or n == 2: | ||
if n in [1, 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 all_fibonacci
refactored with the following changes:
- Replace multiple comparisons of same variable with
in
operator (merge-comparisons
)
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!