-
Notifications
You must be signed in to change notification settings - Fork 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
Sourcery refactored CPython37 branch #1
base: CPython37
Are you sure you want to change the base?
Conversation
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.
Sourcery timed out performing refactorings.
Due to GitHub API limits, only the first 60 comments can be shown.
active = search_mode.consider(dirname, filename) | ||
|
||
if active: | ||
if active := search_mode.consider(dirname, filename): |
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 checkDir
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
)
if line.find("set(attr for attr in dir(g) if not attr.startswith('__')) >= expected") != -1: | ||
return True | ||
elif line.find("isinstance(g, types.GeneratorType)") != -1: | ||
return True | ||
else: | ||
return False | ||
return ( | ||
line.find( | ||
"set(attr for attr in dir(g) if not attr.startswith('__')) >= expected" | ||
) | ||
!= -1 | ||
or line.find( | ||
"set(attr for attr in dir(g) if not attr.startswith('__')) >= expected" | ||
) | ||
== -1 | ||
and line.find("isinstance(g, types.GeneratorType)") != -1 | ||
) |
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 filter_genexps
refactored with the following changes:
- Simplify boolean if expression (
boolean-if-exp-identity
) - Merge duplicate blocks in conditional (
merge-duplicate-blocks
) - Replace if statement with if expression (
assign-if-exp
)
if x < 0: x = 0 | ||
x = max(x, 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 C.setx
refactored with the following changes:
- Replace comparison with min/max call (
min-max-identity
)
if x < 0: x = 0 | ||
x = max(x, 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 C.setx
refactored with the following changes:
- Replace comparison with min/max call (
min-max-identity
)
return [next(g) for i in range(n)] | ||
return [next(g) for _ 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 firstn
refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore
)
for x in self.parent.generator: | ||
yield x | ||
yield from self.parent.generator |
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 disjointSet.generate
refactored with the following changes:
- Replace yield inside for loop with yield from (
yield-from
)
try: | ||
1//0 | ||
except ZeroDivisionError: | ||
yield 666 | ||
except: | ||
pass | ||
1//0 | ||
except ZeroDivisionError: | ||
yield 666 | ||
except: | ||
pass |
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 f
refactored with the following changes:
- Merge nested try-statement into a single try (
flatten-nested-try
)
if 0: | ||
yield | ||
pass |
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 f
refactored with the following changes:
- Remove redundant conditional (
remove-redundant-if
)
if 0: | ||
yield 1 | ||
pass |
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 f
refactored with the following changes:
- Remove redundant conditional (
remove-redundant-if
)
if "": | ||
yield None | ||
pass |
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 f
refactored with the following changes:
- Remove redundant conditional (
remove-redundant-if
)
try: | ||
if x==4: | ||
pass | ||
elif 0: | ||
try: | ||
1//0 | ||
except SyntaxError: | ||
pass | ||
else: | ||
if 0: | ||
while 12: | ||
x += 1 | ||
yield 2 # don't blink | ||
f(a, b, c, d, e) | ||
else: | ||
pass | ||
except: | ||
x = 1 | ||
return |
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 f
refactored with the following changes:
- Remove unreachable code (
remove-unreachable-code
) - Remove redundant conditional (
remove-redundant-if
)
This removes the following comments ( why? ):
# don't blink
if 0: | ||
return | ||
if 0: | ||
yield 2 | ||
pass |
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 f
refactored with the following changes:
- Remove redundant conditional (
remove-redundant-if
)
@@ -1315,7 +1278,6 @@ def f(): | |||
def f(): | |||
yield 1 | |||
return | |||
yield 2 # never reached |
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 f
refactored with the following changes:
- Remove unreachable code (
remove-unreachable-code
)
This removes the following comments ( why? ):
# never reached
for i in range(n): | ||
yield i | ||
yield from 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 yrange
refactored with the following changes:
- Replace yield inside for loop with yield from (
yield-from
)
for i in yrange(n): | ||
yield i | ||
yield from yrange(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 zrange
refactored with the following changes:
- Replace yield inside for loop with yield from (
yield-from
)
for x in {i for i in range(n)}: | ||
yield x | ||
yield from set(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 grange
refactored with the following changes:
- Replace yield inside for loop with yield from (
yield-from
) - Replace identity comprehension with call to collection constructor (
identity-comprehension
)
items = {(lambda: y) for i in range(5)} | ||
items = {lambda: y for _ in range(5)} |
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 test_func
refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore
)
CHECK_TIMINGS = False # making true makes tests take a lot longer | ||
# and can sometimes cause some non-serious | ||
# failures because some calls block a bit | ||
# longer than expected | ||
if CHECK_TIMINGS: | ||
if CHECK_TIMINGS := False: |
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 94-98
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
)
This removes the following comments ( why? ):
# longer than expected
# failures because some calls block a bit
# making true makes tests take a lot longer
# and can sometimes cause some non-serious
exitcode = self._kill_process(multiprocessing.Process.terminate) | ||
if os.name != 'nt': | ||
exitcode = self._kill_process(multiprocessing.Process.terminate) |
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 _TestProcess.test_terminate
refactored with the following changes:
- Move assignments closer to their usage (
move-assign
)
exitcode = self._kill_process(multiprocessing.Process.kill) | ||
if os.name != 'nt': | ||
exitcode = self._kill_process(multiprocessing.Process.kill) |
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 _TestProcess.test_kill
refactored with the following changes:
- Move assignments closer to their usage (
move-assign
)
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 0.06%.
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! |
Branch
CPython37
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
CPython37
branch, then run:Help us improve this pull request!