| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| if n < 2: # base case | ||
| return n | ||
| return fib2(n - 2) + fib2(n - 1) # recursive case | ||
| return n if n < 2 else fib2(n - 2) + fib2(n - 1) |
There was a problem hiding this comment.
Function fib2 refactored with the following changes:
This removes the following comments ( why? ):
# base case # recursive case
Sorry, something went wrong.
| if n < 2: # base case | ||
| return n | ||
| return fib4(n - 2) + fib4(n - 1) # recursive case | ||
| return n if n < 2 else fib4(n - 2) + fib4(n - 1) |
There was a problem hiding this comment.
Function fib4 refactored with the following changes:
This removes the following comments ( why? ):
# base case # recursive case
Sorry, something went wrong.
| self.bit_string |= 0b11 | ||
| else: | ||
| raise ValueError("Invalid Nucleotide:{}".format(nucleotide)) | ||
| raise ValueError(f"Invalid Nucleotide:{nucleotide}") |
There was a problem hiding this comment.
Function CompressedGene._compress refactored with the following changes:
Sorry, something went wrong.
| if bits == 0b00: # A | ||
| if bits == 0b00: | ||
| gene += "A" | ||
| elif bits == 0b01: # C | ||
| elif bits == 0b01: | ||
| gene += "C" | ||
| elif bits == 0b10: # G | ||
| elif bits == 0b10: | ||
| gene += "G" | ||
| elif bits == 0b11: # T | ||
| elif bits == 0b11: | ||
| gene += "T" | ||
| else: | ||
| raise ValueError("Invalid bits:{}".format(bits)) | ||
| raise ValueError(f"Invalid bits:{bits}") |
There was a problem hiding this comment.
Function CompressedGene.decompress refactored with the following changes:
This removes the following comments ( why? ):
# C # T # G # A
Sorry, something went wrong.
| print("original is {} bytes".format(getsizeof(original))) | ||
| print(f"original is {getsizeof(original)} bytes") | ||
| compressed: CompressedGene = CompressedGene(original) # compress | ||
| print("compressed is {} bytes".format(getsizeof(compressed.bit_string))) | ||
| print(f"compressed is {getsizeof(compressed.bit_string)} bytes") | ||
| print(compressed) # decompress | ||
| print("original and decompressed are the same: {}".format(original == compressed.decompress())) No newline at end of file | ||
| print( | ||
| f"original and decompressed are the same: {original == compressed.decompress()}" | ||
| ) No newline at end of file |
There was a problem hiding this comment.
Lines 60-64 refactored with the following changes:
Sorry, something went wrong.
| possible_digits: Dict[str, List[int]] = {} | ||
| for letter in letters: | ||
| possible_digits[letter] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | ||
| possible_digits: Dict[str, List[int]] = { | ||
| letter: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] for letter in letters | ||
| } | ||
|
|
There was a problem hiding this comment.
Lines 49-51 refactored with the following changes:
Sorry, something went wrong.
| def generate_grid(rows: int, columns: int) -> Grid: | ||
| # initialize grid with random letters | ||
| return [[choice(ascii_uppercase) for c in range(columns)] for r in range(rows)] | ||
| return [[choice(ascii_uppercase) for _ in range(columns)] for _ in range(rows)] |
There was a problem hiding this comment.
Function generate_grid refactored with the following changes:
Sorry, something went wrong.
| locations: Dict[str, List[List[GridLocation]]] = {} | ||
| for word in words: | ||
| locations[word] = generate_domain(word, grid) | ||
| locations: Dict[str, List[List[GridLocation]]] = { | ||
| word: generate_domain(word, grid) for word in words | ||
| } | ||
|
|
There was a problem hiding this comment.
Lines 77-79 refactored with the following changes:
Sorry, something went wrong.
| for i in range(len(distances)): | ||
| distance_dict[wg.vertex_at(i)] = distances[i] | ||
| return distance_dict | ||
| return {wg.vertex_at(i): distances[i] for i in range(len(distances))} |
There was a problem hiding this comment.
Function distance_array_to_vertex_dict refactored with the following changes:
Sorry, something went wrong.
| edge_path: WeightedPath = [] | ||
| e: WeightedEdge = path_dict[end] | ||
| edge_path.append(e) | ||
| edge_path: WeightedPath = [e] |
There was a problem hiding this comment.
Function path_dict_to_path refactored with the following changes:
Sorry, something went wrong.
| desc: str = "" | ||
| for i in range(self.vertex_count): | ||
| desc += f"{self.vertex_at(i)} -> {self.neighbors_for_index(i)}\n" | ||
| return desc | ||
| return "".join( | ||
| f"{self.vertex_at(i)} -> {self.neighbors_for_index(i)}\n" | ||
| for i in range(self.vertex_count) | ||
| ) |
There was a problem hiding this comment.
Function Graph.__str__ refactored with the following changes:
Sorry, something went wrong.
|
|
||
| def total_weight(wp: WeightedPath) -> float: | ||
| return sum([e.weight for e in wp]) | ||
| return sum(e.weight for e in wp) |
There was a problem hiding this comment.
Function total_weight refactored with the following changes:
Sorry, something went wrong.
| distance_tuples: List[Tuple[V, float]] = [] | ||
| for edge in self.edges_for_index(index): | ||
| distance_tuples.append((self.vertex_at(edge.v), edge.weight)) | ||
| return distance_tuples | ||
| return [ | ||
| (self.vertex_at(edge.v), edge.weight) | ||
| for edge in self.edges_for_index(index) | ||
| ] |
There was a problem hiding this comment.
Function WeightedGraph.neighbors_for_index_with_weights refactored with the following changes:
Sorry, something went wrong.
| desc: str = "" | ||
| for i in range(self.vertex_count): | ||
| desc += f"{self.vertex_at(i)} -> {self.neighbors_for_index_with_weights(i)}\n" | ||
| return desc | ||
| return "".join( | ||
| f"{self.vertex_at(i)} -> {self.neighbors_for_index_with_weights(i)}\n" | ||
| for i in range(self.vertex_count) | ||
| ) |
There was a problem hiding this comment.
Function WeightedGraph.__str__ refactored with the following changes:
Sorry, something went wrong.
| else: # otherwise mutate y | ||
| if random() > 0.5: | ||
| self.y += 1 | ||
| else: | ||
| self.y -= 1 | ||
| elif random() > 0.5: | ||
| self.y += 1 | ||
| else: | ||
| self.y -= 1 |
There was a problem hiding this comment.
Function SimpleEquation.mutate refactored with the following changes:
This removes the following comments ( why? ):
# otherwise mutate y
Sorry, something went wrong.
| segment: List[Tuple[int, int]] = [] | ||
| for t in range(segment_length): | ||
| segment.append((c, r + t)) | ||
| segment: List[Tuple[int, int]] = [(c, r + t) for t in range(segment_length)] | ||
| segments.append(segment) | ||
|
|
||
| # generate the horizontal segments | ||
| for c in range(num_columns - segment_length + 1): | ||
| for r in range(num_rows): | ||
| segment = [] | ||
| for t in range(segment_length): | ||
| segment.append((c + t, r)) | ||
| segment = [(c + t, r) for t in range(segment_length)] | ||
| segments.append(segment) | ||
|
|
||
| # generate the bottom left to top right diagonal segments | ||
| for c in range(num_columns - segment_length + 1): | ||
| for r in range(num_rows - segment_length + 1): | ||
| segment = [] | ||
| for t in range(segment_length): | ||
| segment.append((c + t, r + t)) | ||
| segment = [(c + t, r + t) for t in range(segment_length)] | ||
| segments.append(segment) | ||
|
|
||
| # generate the top left to bottom right diagonal segments | ||
| for c in range(num_columns - segment_length + 1): | ||
| for r in range(segment_length - 1, num_rows): | ||
| segment = [] | ||
| for t in range(segment_length): | ||
| segment.append((c + t, r - t)) | ||
| segment = [(c + t, r - t) for t in range(segment_length)] |
There was a problem hiding this comment.
Function generate_segments refactored with the following changes:
Sorry, something went wrong.
| total: float = 0 | ||
| for segment in C4Board.SEGMENTS: | ||
| total += self._evaluate_segment(segment, player) | ||
| return total | ||
| return sum( | ||
| self._evaluate_segment(segment, player) for segment in C4Board.SEGMENTS | ||
| ) |
There was a problem hiding this comment.
Function C4Board.evaluate refactored with the following changes:
Sorry, something went wrong.
| display += f"{self.position[c][r]}" + "|" | ||
| display += f"{self.position[c][r]}|" |
There was a problem hiding this comment.
Function C4Board.__repr__ refactored with the following changes:
Sorry, something went wrong.
| if self.is_win and self.turn == player: | ||
| return -1 | ||
| elif self.is_win and self.turn != player: | ||
| elif self.is_win: |
There was a problem hiding this comment.
Function TTTBoard.evaluate refactored with the following changes:
Sorry, something went wrong.
| letter_tuples: List[Tuple[str, ...]] = [] | ||
| for digit in phone_number: | ||
| letter_tuples.append(phone_mapping.get(digit, (digit,))) | ||
| letter_tuples: List[Tuple[str, ...]] = [ | ||
| phone_mapping.get(digit, (digit,)) for digit in phone_number | ||
| ] | ||
|
|
There was a problem hiding this comment.
Function possible_mnemonics refactored with the following changes:
Sorry, something went wrong.
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 0.29%.
Here are some functions in these files that still need a tune-up:
Legend and ExplanationThe emojis denote the absolute quality of the code:
The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request. Please see our documentation here for details on how these metrics are calculated. We are actively working on this report - lots more documentation and extra metrics to come! Help us improve this quality report! |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
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 locallyReduce the feedback loop during development by using the Sourcery editor plugin:
- VS Code
- PyCharm
Review changes via command lineTo manually merge these changes, make sure you're on the master branch, then run:
Help us improve this pull request!