-
Notifications
You must be signed in to change notification settings - Fork 0
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 #1
base: master
Are you sure you want to change the base?
Conversation
print('Number of subsets: {}'.format(len(solutions))) | ||
print(f'Number of subsets: {len(solutions)}') |
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 call to format with f-string (
use-fstring-for-formatting
)
for x in range(0, 20): | ||
for x in range(20): |
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 range(0, x) with range(x) [×5] (
remove-zero-from-range
) - Use f-string instead of string concatenation [×18] (
use-fstring-for-concatenation
) - Remove unnecessary casts to int, str, float or bool [×7] (
remove-unnecessary-cast
)
difference = ( | ||
((p2.x - origin.x) * (p1.y - origin.y)) | ||
- ((p1.x - origin.x) * (p2.y - origin.y)) | ||
return ((p2.x - origin.x) * (p1.y - origin.y)) - ( | ||
(p1.x - origin.x) * (p2.y - origin.y) | ||
) | ||
|
||
return difference |
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 ConvexHull._get_orientation
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
# get the first point (initial max) to use to compare with others | ||
p1 = None | ||
for p in points: | ||
if p is point: | ||
continue | ||
else: | ||
p1 = p | ||
break | ||
|
||
p1 = next((p for p in points if p is not point), None) | ||
far_point = p1 | ||
|
||
for p2 in points: | ||
# ensure we aren't comparing to self or pivot point | ||
if p2 is point or p2 is p1: | ||
continue | ||
else: | ||
direction = self._get_orientation(point, far_point, p2) | ||
if direction > 0: | ||
far_point = p2 | ||
direction = self._get_orientation(point, far_point, p2) | ||
if direction > 0: | ||
far_point = p2 |
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 ConvexHull.compute_hull
refactored with the following changes:
- Use the built-in function
next
instead of a for-loop (use-next
) - Remove redundant continue statement (
remove-redundant-continue
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
)
This removes the following comments ( why? ):
# get the first point (initial max) to use to compare with others
# ensure we aren't comparing to self or pivot point
else: | ||
# path compression | ||
self.hierarchy[item_id] = self.find(self.hierarchy[item_id]) | ||
return self.hierarchy[item_id] | ||
# path compression | ||
self.hierarchy[item_id] = self.find(self.hierarchy[item_id]) | ||
return self.hierarchy[item_id] |
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 DisjointSets.find
refactored with the following changes:
- Remove unnecessary else after guard condition (
remove-unnecessary-else
)
if n <= 2: | ||
return 1 | ||
|
||
return fib(n - 1) + fib(n - 2) | ||
return 1 if n <= 2 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:
- Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
for v in self.adjacency_list: | ||
yield v | ||
yield from self.adjacency_list |
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 DirectedGraph.get_vertex
refactored with the following changes:
- Replace yield inside for loop with yield from (
yield-from
)
for u in self.adjacency_list[vertex]: | ||
yield u | ||
yield from self.adjacency_list[vertex] |
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 DirectedGraph.get_neighbor
refactored with the following changes:
- Replace yield inside for loop with yield from (
yield-from
)
for u in reversed_list[vertex]: | ||
yield u | ||
yield from reversed_list[vertex] |
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 DirectedGraph.get_reverse_neighbor
refactored with the following changes:
- Replace yield inside for loop with yield from (
yield-from
)
for u in self.get_neighbor(v): | ||
if u not in statuses: | ||
to_visit.append(u) | ||
|
||
to_visit.extend(u for u in self.get_neighbor(v) if u not in statuses) |
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 DirectedGraph.topological_sort
refactored with the following changes:
- Replace a for append loop with list extend (
for-append-to-extend
)
components = self.scc_dfs_reverse_pass(stack) | ||
|
||
return components | ||
return self.scc_dfs_reverse_pass(stack) |
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 DirectedGraph.strongly_connected_components
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
for i in range(vertices): | ||
self.adjacency_matrix.append([0] * vertices) | ||
self.adjacency_matrix.extend([0] * vertices for _ in range(vertices)) |
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 UndirectedGraph.__init__
refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore
) - Replace a for append loop with list extend (
for-append-to-extend
)
colorings = {} | ||
to_visit = queue.Queue() | ||
to_visit.put(0) | ||
colorings[0] = 0 | ||
|
||
colorings = {0: 0} |
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 UndirectedGraph.is_bipartite
refactored with the following changes:
- Move assignment closer to its usage within a block (
move-assign-in-block
) - Merge dictionary assignment with declaration (
merge-dict-assign
)
for e in self.adjacency_list[vertex]: | ||
yield e | ||
yield from self.adjacency_list[vertex] |
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 GraphUndirectedWeighted.get_neighbor
refactored with the following changes:
- Replace yield inside for loop with yield from (
yield-from
)
for v in range(self.vertex_count): | ||
yield v | ||
yield from range(self.vertex_count) |
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 GraphUndirectedWeighted.get_vertex
refactored with the following changes:
- Replace yield inside for loop with yield from (
yield-from
)
output += str(current) + " -> " | ||
output += f"{str(current)} -> " |
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 LinkedList.__str__
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
count = 0 | ||
for line in sys.stdin: | ||
count += 1 | ||
|
||
count = sum(1 for _ in sys.stdin) |
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 3-6
refactored with the following changes:
- Convert for loop into call to sum() (
sum-comprehension
) - Replace unused for index with underscore (
for-index-underscore
)
return "%s->%s:%s" % (self.source, self.sink, self.capacity) | ||
return f"{self.source}->{self.sink}:{self.capacity}" |
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 Edge.__repr__
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
found = False | ||
for j in arr2: | ||
if i == j: | ||
found = True | ||
break | ||
found = any(i == j for j in arr2) |
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 contain_same_ints
refactored with the following changes:
- Use any() instead of for loop (
use-any
)
found = False | ||
for j in arr2: | ||
if i == j: | ||
found = True | ||
found = any(i == j for j in arr2) |
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 contain_same_ints
refactored with the following changes:
- Use any() instead of for loop (
use-any
)
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!