-
Notifications
You must be signed in to change notification settings - Fork 0
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 main branch #3
base: main
Are you sure you want to change the base?
Conversation
for o in expected: assert o in cfg, "missing expected setting: {}".format(o) | ||
for o in expected: | ||
assert o in cfg, f"missing expected setting: {o}" |
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 13-63
refactored with the following changes:
- Replace call to format with f-string [×3] (
use-fstring-for-formatting
) - Use f-string instead of string concatenation [×5] (
use-fstring-for-concatenation
)
if partial_url[0] == "/": | ||
return base_url + partial_url | ||
else: | ||
return partial_url | ||
return base_url + partial_url if partial_url[0] == "/" else partial_url |
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 add_scheme_and_domain
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
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.
PR Type: Refactoring
Summary of PR: This PR introduces refactoring changes made by Sourcery, an automated code review and refactoring tool, to the main
branch of the repository. The changes include the use of f-strings for string formatting, simplification of conditional statements, and restructuring of list and dictionary comprehensions.
General PR suggestions
- Ensure that the use of f-strings in exception messages does not lead to unnecessary expression evaluations. Traditional string formatting with lazy evaluation might be more appropriate in some cases.
- Be cautious with the use of f-strings in regular expressions, especially when dealing with strings that may contain regex metacharacters. Proper escaping is necessary to avoid potential bugs.
- Consider the readability of one-liner conditional statements. In some cases, the original multi-line if-else blocks may be more readable and maintainable.
- When using methods like
cfg.get
to provide default values, ensure that the defaults are appropriate for the application's requirements and won't lead to unexpected behavior. - Review the changes for consistency and adherence to the project's coding standards, as automated refactoring tools may not always align with project-specific guidelines.
Your trial expires on December 14, 2023. Please email tim@sourcery.ai to continue using Sourcery ✨
@@ -10,7 +10,8 @@ | |||
|
|||
cfg_keys = 'version description keywords author author_email'.split() | |||
expected = cfg_keys + "lib_name user branch license status min_python audience language".split() | |||
for o in expected: assert o in cfg, "missing expected setting: {}".format(o) | |||
for o in expected: | |||
assert o in cfg, f"missing expected setting: {o}" |
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.
suggestion (llm): Using f-strings for exceptions is not recommended as it can lead to the evaluation of expressions that might not be needed if the assertion does not fail. Consider using the traditional formatting which evaluates lazily.
assert o in cfg, f"missing expected setting: {o}" | |
assert o in cfg, "missing expected setting: %s" % o |
long_description = re.sub(r'src=\"(.*)\.'+ext+'\"', 'src=\"https://raw.githubusercontent.com/{}/{}'.format(cfg['user'],cfg['lib_name'])+'/'+cfg['branch']+'/\\1.'+ext+'\"', long_description) | ||
long_description = re.sub( | ||
r'!\[' + ext + '\]\((.*)\)', | ||
f'![{ext}](' |
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.
issue (llm): The refactored regular expression replacement using f-strings may introduce a bug if 'ext' contains special regex characters. Ensure that 'ext' is properly escaped if it's expected to contain regex metacharacters.
return base_url + partial_url | ||
else: | ||
return partial_url | ||
return base_url + partial_url if partial_url[0] == "/" else partial_url |
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.
suggestion (llm): The refactored one-liner for URL concatenation is less readable than the original if-else block. Consider reverting to the original block or using a more readable approach.
return base_url + partial_url if partial_url[0] == "/" else partial_url | |
- return base_url + partial_url if partial_url[0] == "/" else partial_url |
long_description=long_description, | ||
long_description_content_type='text/markdown', | ||
zip_safe=False, | ||
entry_points={'console_scripts': cfg.get('console_scripts', '').split()}, |
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.
thought (llm): The change to use 'cfg.get' for 'console_scripts' is good for handling missing keys, but ensure that the default empty string is an appropriate fallback for your application's needs.
Branch
main
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
main
branch, then run:Help us improve this pull request!