Sourcery refactored main branch#1
Conversation
| if isinstance(vec[0], ValType): | ||
| return vec | ||
| return [t for name,t in vec] | ||
| return vec if isinstance(vec[0], ValType) else [t for name,t in vec] |
There was a problem hiding this comment.
Function FuncType.extract_types 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 n <= 16: return 2 | ||
| return 4 | ||
| return 2 if n <= 16 else 4 |
There was a problem hiding this comment.
Function alignment_flags 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 n <= 16: return 2 | ||
| return 4 * num_i32_flags(labels) | ||
| return 2 if n <= 16 else 4 * num_i32_flags(labels) |
There was a problem hiding this comment.
Function size_flags 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)
| self.rt_to_table = dict() | ||
| self.rt_to_table = {} |
There was a problem hiding this comment.
Function HandleTables.__init__ refactored with the following changes:
- Replace
dict()with{}(dict-literal)
| if math.isnan(f): | ||
| return reinterpret_i32_as_float(CANONICAL_FLOAT32_NAN) | ||
| return f | ||
| return reinterpret_i32_as_float(CANONICAL_FLOAT32_NAN) if math.isnan(f) else f |
There was a problem hiding this comment.
Function canonicalize32 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)
| i = vi.next('i' + str(core_width)) | ||
| i = vi.next(f'i{str(core_width)}') |
There was a problem hiding this comment.
Function lift_flat_unsigned refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| i = vi.next('i' + str(core_width)) | ||
| i = vi.next(f'i{str(core_width)}') | ||
| assert(0 <= i < (1 << core_width)) | ||
| i %= (1 << t_width) | ||
| if i >= (1 << (t_width - 1)): | ||
| return i - (1 << t_width) | ||
| return i | ||
| return i - (1 << t_width) if i >= (1 << (t_width - 1)) else i |
There was a problem hiding this comment.
Function lift_flat_signed refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation) - Lift code into else after jump in control flow (
reintroduce-else) - Replace if statement with if expression (
assign-if-exp)
| record = {} | ||
| for f in fields: | ||
| record[f.label] = lift_flat(cx, vi, f.t) | ||
| return record | ||
| return {f.label: lift_flat(cx, vi, f.t) for f in fields} |
There was a problem hiding this comment.
Function lift_flat_record refactored with the following changes:
- Convert for loop into dictionary comprehension (
dict-comprehension) - Inline variable that is immediately returned (
inline-immediately-returned-variable)
| if c.t is None: | ||
| v = None | ||
| else: | ||
| v = lift_flat(cx, CoerceValueIter(), c.t) | ||
| v = None if c.t is None else lift_flat(cx, CoerceValueIter(), c.t) |
There was a problem hiding this comment.
Function lift_flat_variant refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| return [Value('i' + str(core_bits), i)] | ||
| return [Value(f'i{str(core_bits)}', i)] |
There was a problem hiding this comment.
Function lower_flat_signed refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| if c.t is None: | ||
| payload = [] | ||
| else: | ||
| payload = lower_flat(cx, case_value, c.t) | ||
| payload = [] if c.t is None else lower_flat(cx, case_value, c.t) |
There was a problem hiding this comment.
Function lower_flat_variant refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| if len(flat_types) > max_flat: | ||
| ptr = vi.next('i32') | ||
| tuple_type = Tuple(ts) | ||
| trap_if(ptr != align_to(ptr, alignment(tuple_type))) | ||
| trap_if(ptr + size(tuple_type) > len(cx.opts.memory)) | ||
| return list(load(cx, ptr, tuple_type).values()) | ||
| else: | ||
| if len(flat_types) <= max_flat: | ||
| return [ lift_flat(cx, vi, t) for t in ts ] | ||
| ptr = vi.next('i32') | ||
| tuple_type = Tuple(ts) | ||
| trap_if(ptr != align_to(ptr, alignment(tuple_type))) | ||
| trap_if(ptr + size(tuple_type) > len(cx.opts.memory)) | ||
| return list(load(cx, ptr, tuple_type).values()) |
There was a problem hiding this comment.
Function lift_values refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches) - Remove unnecessary else after guard condition (
remove-unnecessary-else)
| self.last_alloc = ret + new_size | ||
| if self.last_alloc > len(self.memory): | ||
| print('oom: have {} need {}'.format(len(self.memory), self.last_alloc)) | ||
| print(f'oom: have {len(self.memory)} need {self.last_alloc}') |
There was a problem hiding this comment.
Function Heap.realloc refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| elif src_encoding == 'utf16': | ||
| encoded = s.encode('utf-16-le') | ||
| tagged_code_units = int(len(encoded) / 2) | ||
| tagged_code_units = len(encoded) // 2 |
There was a problem hiding this comment.
Function test_string refactored with the following changes:
- Simplify division expressions [×2] (
simplify-division)
|
|
||
| if got != v: | ||
| fail("test_roundtrip({},{},{}) got {}".format(t, v, caller_args, got)) | ||
| fail(f"test_roundtrip({t},{v},{caller_args}) got {got}") |
There was a problem hiding this comment.
Function test_roundtrip refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
Branch
mainrefactored 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
mainbranch, then run:Help us improve this pull request!