Sourcery refactored master branch#407
Conversation
| for i in range(sess.run(global_step), max_epoch): | ||
| for j in range(int(60000 // batch_size)): | ||
| print("epoch:%s, iter:%s" % (i, j)) | ||
| print(f"epoch:{i}, iter:{j}") |
There was a problem hiding this comment.
Function train refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
| print("### error: can only plot 2D data", file=sys.stderr) | ||
| sys.exit(1) | ||
| center = data[0:2] | ||
| center = data[:2] |
There was a problem hiding this comment.
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.
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)
| version = 'NETCDF3_CLASSIC' | ||
| else: | ||
| version = 'NETCDF4' | ||
| version = 'NETCDF3_CLASSIC' if options.version == '3' else 'NETCDF4' |
There was a problem hiding this comment.
Lines 20-23 refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| while True: | ||
| avail_nucls = available_nucl(nucl_left) | ||
| if avail_nucls: | ||
| if avail_nucls := available_nucl(nucl_left): |
There was a problem hiding this comment.
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.
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)
| 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.
Function fac refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| print('resources: ' + ', '.join(specs)) | ||
| if options.account: | ||
| print('account: ' + options.account) | ||
| print(f'account: {options.account}') |
There was a problem hiding this comment.
Lines 22-22 refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
|
|
||
| def parse_job_script(file_name): | ||
| args = list() | ||
| args = [] |
There was a problem hiding this comment.
Function parse_job_script refactored with the following changes:
- Replace
list()with[](list-literal)
| 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.
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.
Function main refactored with the following changes:
- Remove unreachable code (
remove-unreachable-code)
| 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.
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.
Lines 37-37 refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore)
| total = 0.0 | ||
| start_time = timeit.default_timer() | ||
| for iter_nr in range(options.iter): | ||
| for _ in range(options.iter): |
There was a problem hiding this comment.
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.
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.
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.
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.
Function write_vcd_data_structure refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension) - Replace
list()with[](list-literal)
| 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.
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)
| } | ||
| args = shlex.split(arg_str) | ||
| if len(args) != 1 and len(args) != 3: | ||
| if len(args) not in [1, 3]: |
There was a problem hiding this comment.
Function ExperimentShell.parse_show_arg refactored with the following changes:
- Replace multiple comparisons of same variable with
inoperator (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.
Function ExperimentShell.do_show refactored with the following changes:
- Merge else clause's nested if statement into elif (
merge-else-if-into-elif)
| researcher.first_name)) | ||
| for sample in experiment.samples: | ||
| print('\t{}'.format(sample.description)) | ||
| print(f'\t{sample.description}') |
There was a problem hiding this comment.
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.
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)
| 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.
Function fact refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| 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.
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.
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.
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.
Function identify_domains refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension)
| 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.
Function main refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| n_1 = 1 | ||
| for n in itertools.count(1): | ||
| if n == 1 or n == 2: | ||
| if n in [1, 2]: |
There was a problem hiding this comment.
Function all_fibonacci refactored with the following changes:
- Replace multiple comparisons of same variable with
inoperator (merge-comparisons)
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!