-
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 develop branch #1
base: develop
Are you sure you want to change the base?
Conversation
raise ValueError("invalid node %s in filter expression" % node) | ||
raise ValueError(f"invalid node {node} in filter expression") |
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_invalid_node
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
assert False, "unexpected boolean operator %s" % node.op | ||
assert False, f"unexpected boolean operator {node.op}" |
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 _FilterVisitor.visit_BoolOp
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
raise ValueError( | ||
"expected a string on left side of %s" % node.op) | ||
raise ValueError(f"expected a string on left side of {node.op}") | ||
if not isinstance(right, str): | ||
raise ValueError( | ||
"expected a string on right side of %s" % node.op) | ||
raise ValueError(f"expected a string on right side of {node.op}") |
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 _FilterVisitor.visit_BinOp
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
elif id_ == 'author' or id_ == 'editor': | ||
elif id_ in ['author', 'editor']: |
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 _FilterVisitor.visit_Name
refactored with the following changes:
- Replace multiple comparisons of same variable with
in
operator (merge-comparisons
)
for docname in sorted(env.found_docs - docnames): | ||
yield docname | ||
yield from sorted(env.found_docs - docnames) |
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_docnames
refactored with the following changes:
- Replace yield inside for loop with yield from (
yield-from
)
return '<%s>' % self.__str__() | ||
return f'<{self.__str__()}>' |
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 CitationTransform.__repr__
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
author = u'%s et al.' % authors[0].last_names[0] | ||
author = f'{authors[0].last_names[0]} et al.' | ||
elif len(authors) == 1: | ||
author = authors[0].last_names[0] | ||
else: | ||
author = u"%s and %s" % ( | ||
u', '.join([a.last_names[0] for a in authors[:-1]]), | ||
authors[-1].last_names[0]) | ||
author = f"{u', '.join([a.last_names[0] for a in authors[:-1]])} and {authors[-1].last_names[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 CitationTransform.get_author
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
def cite(self, cmd, refuri, global_keys): # noqa: C901 | ||
def cite(self, cmd, refuri, global_keys): # noqa: C901 | ||
""" | ||
Return a docutils Node consisting of properly formatted citations | ||
children nodes. | ||
""" | ||
self.global_keys = global_keys | ||
bo, bc = self.config['brackets'] | ||
sep = u'%s ' % self.config['separator'] | ||
sep = f"{self.config['separator']} " |
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 CitationTransform.cite
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
) - Use f-string instead of string concatenation (
use-fstring-for-concatenation
) - Swap positions of nested conditionals (
swap-nested-ifs
) - Hoist repeated code outside conditional statement (
hoist-statement-from-if
) - Replace if statement with if expression (
assign-if-exp
) - Merge duplicate blocks in conditional (
merge-duplicate-blocks
) - Swap if/else to remove empty if body (
remove-pass-body
)
if len(authorsort) > 0: | ||
if authorsort != '': |
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 sort_references.sortkey
refactored with the following changes:
- Simplify comparison to string length (
simplify-str-len-comparison
)
config = {} | ||
for opt in ['style', 'brackets', 'separator', 'sort', 'sort_compress']: | ||
config[opt] = env.temp_data.get( | ||
"cite_%s" % opt, | ||
env.domaindata['cite']['conf'].get( | ||
opt, DEFAULT_CONF[opt])) | ||
config = { | ||
opt: env.temp_data.get( | ||
f"cite_{opt}", | ||
env.domaindata['cite']['conf'].get(opt, DEFAULT_CONF[opt]), | ||
) | ||
for opt in ['style', 'brackets', 'separator', 'sort', 'sort_compress'] | ||
} |
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 CitationXRefRole.result_nodes
refactored with the following changes:
- Convert for loop into dictionary comprehension (
dict-comprehension
) - Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
env.temp_data['cite_%s' % k] = v | ||
env.temp_data[f'cite_{k}'] = v |
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 CitationConfDirective.run
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
ending = '%s ' % ('' if text.endswith('.') else '.') | ||
ending = f"{'' if text.endswith('.') else '.'} " |
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 CitationReferencesDirective.get_reference_node
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
nid = "citation-%s" % nodes.make_id(key) | ||
nid = f"citation-{nodes.make_id(key)}" |
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 CitationReferencesDirective.run
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
refdoc = self.data['refdoc'] | ||
if not refdoc: | ||
if refdoc := self.data['refdoc']: | ||
refuri = builder.get_relative_uri(fromdocname, refdoc) | ||
|
||
else: | ||
logger.warning( | ||
'no `refs` directive found; citations will have dead links', | ||
location=node) | ||
refuri = '' | ||
else: | ||
refuri = builder.get_relative_uri(fromdocname, refdoc) | ||
|
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 CitationDomain.resolve_xref
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
) - Swap if/else branches (
swap-if-else-branches
)
text = ".*" + title + ".*" | ||
text = f".*{title}.*" |
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_autodoc
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
assert [line for line in output.split('\n')][1:] == [ | ||
assert list(output.split('\n'))[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 test_debug_minimal_example
refactored with the following changes:
- Replace identity comprehension with call to collection constructor (
identity-comprehension
)
assert str(join.format()) == "" | ||
assert not str(join.format()) |
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_join
refactored with the following changes:
- Replaces an empty collection equality with a boolean operation. (
simplify-empty-collection-comparison
)
assert str(sentence.format()) == "" | ||
assert not str(sentence.format()) |
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_sentence
refactored with the following changes:
- Replaces an empty collection equality with a boolean operation. (
simplify-empty-collection-comparison
)
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 0.94%.
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
develop
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
develop
branch, then run:Help us improve this pull request!