Sourcery refactored master branch#1
Conversation
| for x in tree['contents']: | ||
| for y in flatten_tree(x): | ||
| yield y | ||
| yield from flatten_tree(x) |
There was a problem hiding this comment.
Function flatten_tree refactored with the following changes:
- Replace yield inside for loop with yield from (
yield-from)
| if 'contents' in tree: | ||
| x = tree['contents'][0] | ||
| return first_leaf(x) | ||
| else: | ||
| if 'contents' not in tree: | ||
| return tree | ||
| x = tree['contents'][0] | ||
| return first_leaf(x) |
There was a problem hiding this comment.
Function first_leaf refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches) - Remove unnecessary else after guard condition (
remove-unnecessary-else)
| if page is None: | ||
| uri = f'/books/{book}' | ||
| else: | ||
| uri = f'/books/{book}/pages/{page}' | ||
| return uri | ||
| return f'/books/{book}' if page is None else f'/books/{book}/pages/{page}' |
There was a problem hiding this comment.
Function rex_uri refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp) - Inline variable that is immediately returned (
inline-immediately-returned-variable)
| if page is None: | ||
| uri_regex = f"/contents/({book['id']}|{book['short_id']})(@[.\d]+)?(/[-%\w\d]+)?$" | ||
| else: | ||
| uri_regex = f"/contents/({book['id']}|{book['short_id']})(@[.\d]+)?:({page['id']}|{page['short_id']})(@[.\d]+)?(/[-%\w\d]+)?$" | ||
| return uri_regex | ||
| return ( | ||
| f"/contents/({book['id']}|{book['short_id']})(@[.\d]+)?(/[-%\w\d]+)?$" | ||
| if page is None | ||
| else f"/contents/({book['id']}|{book['short_id']})(@[.\d]+)?:({page['id']}|{page['short_id']})(@[.\d]+)?(/[-%\w\d]+)?$" | ||
| ) |
There was a problem hiding this comment.
Function cnx_uri_regex refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp) - Inline variable that is immediately returned (
inline-immediately-returned-variable)
| class CalledProcessError(Exception): | ||
| pass | ||
| if not res == 0: | ||
| if res != 0: |
There was a problem hiding this comment.
Function _check_call_py24 refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan)
| try: | ||
| subprocess.check_call(cmd, stdout=devnull, stderr=devnull) | ||
| except: | ||
| return False | ||
| subprocess.check_call(cmd, stdout=devnull, stderr=devnull) | ||
| except: | ||
| return False |
There was a problem hiding this comment.
Function has_powershell refactored with the following changes:
- Merge nested try-statement into a single try (
flatten-nested-try)
| try: | ||
| subprocess.check_call(cmd, stdout=devnull, stderr=devnull) | ||
| except: | ||
| return False | ||
| subprocess.check_call(cmd, stdout=devnull, stderr=devnull) | ||
| except: | ||
| return False |
There was a problem hiding this comment.
Function has_curl refactored with the following changes:
- Merge nested try-statement into a single try (
flatten-nested-try)
| return False | ||
| subprocess.check_call(cmd, stdout=devnull, stderr=devnull) | ||
| except: | ||
| return False |
There was a problem hiding this comment.
Function has_wget refactored with the following changes:
- Merge nested try-statement into a single try (
flatten-nested-try)
Branch
masterrefactored 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
masterbranch, then run:Help us improve this pull request!