-
-
Notifications
You must be signed in to change notification settings - Fork 4
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 ultroid branch #2
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.
Due to GitHub API limits, only the first 60 comments can be shown.
for root, _dirs, _files in os.walk(LIBRARY_DIR, topdown=False): | ||
# setuptools is including __pycache__ for some reason (#1605) | ||
if root.endswith('/__pycache__'): | ||
remove_dirs.append(root) | ||
remove_dirs.extend( | ||
root | ||
for root, _dirs, _files in os.walk(LIBRARY_DIR, topdown=False) | ||
if root.endswith('/__pycache__') | ||
) |
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 for append loop with list extend (
for-append-to-extend
) - Replace m.group(x) with m[x] for re.Match objects (
use-getitem-for-re-match-groups
)
This removes the following comments ( why? ):
# setuptools is including __pycache__ for some reason (#1605)
version = re.search(r"^__version__\s+=\s+'(.*)'$", | ||
f.read(), flags=re.MULTILINE).group(1) | ||
version = re.search( | ||
r"^__version__\s+=\s+'(.*)'$", f.read(), flags=re.MULTILINE | ||
)[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.
Lines 77-78
refactored with the following changes:
- Replace m.group(x) with m[x] for re.Match objects (
use-getitem-for-re-match-groups
)
node = nodes.reference(rawtext, utils.unescape(name), | ||
refuri='{}?q={}'.format(base, name), | ||
**options) | ||
return node | ||
return nodes.reference( | ||
rawtext, utils.unescape(name), refuri=f'{base}?q={name}', **options | ||
) |
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 make_link_node
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
) - Replace call to format with f-string (
use-fstring-for-formatting
)
result = self.__dict__.get(utils.get_peer_id(cls(item))) | ||
if result: | ||
if result := self.__dict__.get(utils.get_peer_id(cls(item))): |
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 EntityCache.__getitem__
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
)
parent = os.path.dirname(file_path) | ||
if parent: | ||
if parent := os.path.dirname(file_path): |
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 ensure_parent_dir_exists
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
)
if diff < 0 or \ | ||
diff.bit_length() < min_diff_bits_count or \ | ||
modexp.bit_length() < min_diff_bits_count or \ | ||
(modexp.bit_length() + 7) // 8 > max_mod_exp_size: | ||
return False | ||
return True | ||
return ( | ||
diff >= 0 | ||
and diff.bit_length() >= min_diff_bits_count | ||
and modexp.bit_length() >= min_diff_bits_count | ||
and (modexp.bit_length() + 7) // 8 <= max_mod_exp_size | ||
) |
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 is_good_mod_exp_first
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
) - Simplify boolean if expression (
boolean-if-exp-identity
) - Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast
)
if loop.is_running(): | ||
return coro | ||
else: | ||
return loop.run_until_complete(coro) | ||
return coro if loop.is_running() else loop.run_until_complete(coro) |
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 _syncify_wrap
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
if not name.startswith('_') or name == '__call__': | ||
if inspect.iscoroutinefunction(getattr(t, name)): | ||
_syncify_wrap(t, name) | ||
if ( | ||
not name.startswith('_') or name == '__call__' | ||
) and inspect.iscoroutinefunction(getattr(t, name)): | ||
_syncify_wrap(t, name) |
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 syncify
refactored with the following changes:
- Merge nested if conditions (
merge-nested-ifs
)
return '{} {}'.format(entity.first_name, entity.last_name) | ||
return f'{entity.first_name} {entity.last_name}' |
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 get_display_name
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
raise TypeError('Cannot cast {} to any kind of {}.'.format( | ||
type(entity).__name__, target)) | ||
raise TypeError( | ||
f'Cannot cast {type(entity).__name__} to any kind of {target}.' | ||
) |
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 _raise_cast_fail
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
Branch
ultroid
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
ultroid
branch, then run:Help us improve this pull request!