-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored master branch #1
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
base: master
Are you sure you want to change the base?
Conversation
assert task_failed is True | ||
assert task_failed |
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 schedule_jobs
refactored with the following changes:
- Simplify comparison to boolean (
simplify-boolean-comparison
)
assert time_sleep_called is True | ||
assert time_sleep_called |
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:
- Simplify comparison to boolean (
simplify-boolean-comparison
)
assert call_failed is True | ||
assert call_failed |
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:
- Simplify comparison to boolean (
simplify-boolean-comparison
)
assert calc_failed is True | ||
assert calc_failed |
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:
- Simplify comparison to boolean (
simplify-boolean-comparison
)
assert input_failed is True | ||
assert input_failed |
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:
- Simplify comparison to boolean (
simplify-boolean-comparison
)
assert letters[0:3:2] == ["a", "c"] | ||
assert letters[:3:2] == ["a", "c"] |
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 a[0:x] with a[:x] and a[x:len(a)] with a[x:] (
remove-redundant-slice-index
) - Convert for loop into list comprehension (
list-comprehension
) - Replace identity comprehension with call to collection constructor (
identity-comprehension
)
This removes the following comments ( why? ):
# add 0..4 to the back
# more elements. Lists can also be modified to have less elements
# Notice that lists have variable length and can be modified to have
simple_set = {0, 1, 2} | ||
simple_set = {0, 1, 2, 3} | ||
|
||
# A set is dynamic like a `list` and `tuple` | ||
simple_set.add(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 main
refactored with the following changes:
- Merge add into set declaration (
merge-set-add
) - Simplify sequence length comparison [×2] (
simplify-len-comparison
)
This removes the following comments ( why? ):
# A set is dynamic like a `list` and `tuple`
assert len(content) > 0 | ||
assert content != "" | ||
|
||
# We can use range slices to get substrings from a string | ||
assert content[:8] == "Ultimate" | ||
assert content.startswith("Ultimate") |
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:
- Simplify comparison to string length (
simplify-str-len-comparison
) - Replace str prefix/suffix check with call to
startswith/endswith
(str-prefix-suffix
)
smaller_immutable = immutable[0:2] | ||
smaller_immutable = immutable[: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 main
refactored with the following changes:
- Replace a[0:x] with a[:x] and a[x:len(a)] with a[x:] (
remove-redundant-slice-index
)
x = 1 | ||
x_add_two = x + 2 | ||
x_add_two = 1 + 2 | ||
ran_1 = x_add_two == 3 | ||
assert ran_1 | ||
|
||
# This condition is obviously true | ||
ran_1 = False | ||
if x_add_two == 3: # skip: else | ||
ran_1 = True # run | ||
assert ran_1 is True | ||
|
||
# A negated condition can also be true | ||
ran_2 = False | ||
if not x_add_two == 1: # skip: else | ||
ran_2 = True # run | ||
assert ran_2 is True | ||
ran_2 = x_add_two != 1 | ||
assert ran_2 | ||
|
||
# There are `else` statements as well, which run if the initial condition | ||
# fails. Notice that one line gets skipped and this conditional does not | ||
# help us make a conclusion on the variable's true value | ||
if x_add_two == 1: | ||
ran_3 = False # skip: if | ||
else: | ||
ran_3 = True # run | ||
assert ran_3 is True | ||
ran_3 = x_add_two != 1 | ||
assert ran_3 | ||
|
||
# The `else` statement also runs once all other `if` and `elif` conditions | ||
# fail. Notice that multiple lines get skipped, and that all of the | ||
# conditions could have been compressed to `x_add_two != 3` for | ||
# simplicity. In this case, less logic results in more clarity | ||
if x_add_two == 1: | ||
ran_4 = False # skip: if | ||
elif x_add_two == 2: | ||
ran_4 = False # skip: if | ||
elif x_add_two < 3 or x_add_two > 3: | ||
ran_4 = False # skip: if | ||
else: | ||
ran_4 = True # run | ||
assert ran_4 is True | ||
ran_4 = x_add_two != 1 and x_add_two != 2 and x_add_two >= 3 and x_add_two <= 3 | ||
assert ran_4 |
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:
- Inline variable that is only used once (
inline-variable
) - Move assignment closer to its usage within a block [×2] (
move-assign-in-block
) - Simplify comparison to boolean [×4] (
simplify-boolean-comparison
) - Replace if statement with if expression [×4] (
assign-if-exp
) - Merge duplicate blocks in conditional (
merge-duplicate-blocks
) - Move setting of default value for variable into
else
branch [×2] (introduce-default-else
) - Simplify logical expression using De Morgan identities (
de-morgan
) - Simplify boolean if expression [×4] (
boolean-if-exp-identity
) - Remove redundant conditional (
remove-redundant-if
) - Remove unnecessary casts to int, str, float or bool [×4] (
remove-unnecessary-cast
)
This removes the following comments ( why? ):
# skip: else
# run
# This condition is obviously true
# skip: if
# A negated condition can also be true
assert x + 1 == 2 | ||
assert x == 1 | ||
|
||
# An expression can be chained indefinitely. This concept of chaining | ||
# expressions is powerful because it allows us to compose simple pieces | ||
# of code into larger pieces of code over time | ||
assert x * 2 * 2 * 2 == 8 | ||
assert x == 1 | ||
|
||
# Division is tricky because Python 3.x returns 0.5 of type `float` | ||
# whereas Python 2.x returns 0 of type `int`. If this line fails, it | ||
# is a sign that the wrong version of Python was used | ||
assert x / 2 == 0.5 | ||
assert x == 0.5 * 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 main
refactored with the following changes:
- Simplify numeric comparison [×5] (
simplify-numeric-comparison
)
total = 0 | ||
for i in range(n): | ||
total += fn(i) | ||
return total | ||
return sum(fn(i) for i in range(n)) |
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 sum_until
refactored with the following changes:
- Convert for loop into call to sum() (
sum-comprehension
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
)
# We can use underscores (literal `_`) to separate digit groups in | ||
# integer literals | ||
assert 10_000 == 10000 | ||
assert 0x01_0f_2c == 69_420 |
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
assert True
statements [×2] (remove-assert-true
) - Simplify x == x -> True and x != x -> False [×2] (
equality-identity
)
This removes the following comments ( why? ):
# We can use underscores (literal `_`) to separate digit groups in
# integer literals
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!