Sourcery refactored CPython37 branch#1
Conversation
| active = search_mode.consider(dirname, filename) | ||
|
|
||
| if active: | ||
| if active := search_mode.consider(dirname, filename): |
There was a problem hiding this comment.
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.
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)
|
|
||
| def setx(self, x): | ||
| if x < 0: x = 0 | ||
| x = max(x, 0) |
There was a problem hiding this comment.
Function C.setx refactored with the following changes:
- Replace comparison with min/max call (
min-max-identity)
| return self.__x | ||
| def setx(self, x): | ||
| if x < 0: x = 0 | ||
| x = max(x, 0) |
There was a problem hiding this comment.
Function C.setx refactored with the following changes:
- Replace comparison with min/max call (
min-max-identity)
| try: | ||
| def firstn(g, n): | ||
| return [next(g) for i in range(n)] | ||
| return [next(g) for _ in range(n)] |
There was a problem hiding this comment.
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.
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.
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.
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.
Function f refactored with the following changes:
- Remove redundant conditional (
remove-redundant-if)
| if "": | ||
| yield None | ||
| pass |
There was a problem hiding this comment.
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.
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.
Function f refactored with the following changes:
- Remove redundant conditional (
remove-redundant-if)
| def f(): | ||
| yield 1 | ||
| return | ||
| yield 2 # never reached |
There was a problem hiding this comment.
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.
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.
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.
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.
Function test_func refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore)
| # failures because some calls block a bit | ||
| # longer than expected | ||
| if CHECK_TIMINGS: | ||
| if CHECK_TIMINGS := False: |
There was a problem hiding this comment.
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.
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.
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! |
|
Not working on this code |
Branch
CPython37refactored 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
CPython37branch, then run:Help us improve this pull request!