Skip to content
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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Mar 15, 2022

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:

git fetch origin sourcery/develop
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from xinetzone March 15, 2022 03:23
raise ValueError("invalid node %s in filter expression" % node)
raise ValueError(f"invalid node {node} in filter expression")
Copy link
Author

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:

assert False, "unexpected boolean operator %s" % node.op
assert False, f"unexpected boolean operator {node.op}"
Copy link
Author

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:

Comment on lines -113 to +115
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}")
Copy link
Author

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:

Comment on lines -166 to +164
elif id_ == 'author' or id_ == 'editor':
elif id_ in ['author', 'editor']:
Copy link
Author

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:

Comment on lines -206 to +204
for docname in sorted(env.found_docs - docnames):
yield docname
yield from sorted(env.found_docs - docnames)
Copy link
Author

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)

Comment on lines -121 to +120
return '<%s>' % self.__str__()
return f'<{self.__str__()}>'
Copy link
Author

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:

Comment on lines -133 to +137
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]}"

Copy link
Author

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:

Comment on lines -145 to +150
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']} "
Copy link
Author

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:

Comment on lines -237 to +228
if len(authorsort) > 0:
if authorsort != '':
Copy link
Author

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:

Comment on lines -263 to +260
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']
}
Copy link
Author

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:

Comment on lines -331 to +325
env.temp_data['cite_%s' % k] = v
env.temp_data[f'cite_{k}'] = v
Copy link
Author

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:

Comment on lines -373 to +367
ending = '%s ' % ('' if text.endswith('.') else '.')
ending = f"{'' if text.endswith('.') else '.'} "
Copy link
Author

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:

Comment on lines -443 to +437
nid = "citation-%s" % nodes.make_id(key)
nid = f"citation-{nodes.make_id(key)}"
Copy link
Author

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:

Comment on lines -501 to -509
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)

Copy link
Author

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:

text = ".*" + title + ".*"
text = f".*{title}.*"
Copy link
Author

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:

assert [line for line in output.split('\n')][1:] == [
assert list(output.split('\n'))[1:] == [
Copy link
Author

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:

assert str(join.format()) == ""
assert not str(join.format())
Copy link
Author

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:

assert str(sentence.format()) == ""
assert not str(sentence.format())
Copy link
Author

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:

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Mar 15, 2022

Sourcery Code Quality Report

✅  Merging this PR will increase code quality in the affected files by 0.94%.

Quality metrics Before After Change
Complexity 10.87 🙂 9.91 🙂 -0.96 👍
Method Length 64.03 🙂 63.76 🙂 -0.27 👍
Working memory 10.44 😞 10.39 😞 -0.05 👍
Quality 59.63% 🙂 60.57% 🙂 0.94% 👍
Other metrics Before After Change
Lines 1556 1539 -17
Changed files Quality Before Quality After Quality Change
src/sphinxcontrib/bibtex/domain.py 71.06% 🙂 71.24% 🙂 0.18% 👍
src/sphinxcontrib/bibtex/foot_directives.py 61.71% 🙂 65.53% 🙂 3.82% 👍
src/sphinxcontrib/bibtex/foot_domain.py 85.19% ⭐ 85.96% ⭐ 0.77% 👍
src/sphinxcontrib/bibtex/foot_roles.py 30.93% 😞 33.60% 😞 2.67% 👍
src/sphinxcontrib/bibtex/transforms.py 33.24% 😞 34.59% 😞 1.35% 👍
src/sphinxcontrib/bibtex/style/template.py 81.54% ⭐ 81.30% ⭐ -0.24% 👎
test/natbib.py 46.74% 😞 47.94% 😞 1.20% 👍
test/test_autodoc.py 62.41% 🙂 62.41% 🙂 0.00%
test/test_debug.py 87.81% ⭐ 87.86% ⭐ 0.05% 👍
test/test_template.py 83.27% ⭐ 83.42% ⭐ 0.15% 👍

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
test/natbib.py CitationTransform.cite 54 ⛔ 390 ⛔ 17 ⛔ 10.39% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
src/sphinxcontrib/bibtex/transforms.py BibliographyTransform.run 25 😞 235 ⛔ 20 ⛔ 22.64% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
test/natbib.py CitationReferencesDirective.get_reference_node 23 😞 400 ⛔ 13 😞 25.92% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
src/sphinxcontrib/bibtex/foot_roles.py FootCiteRole.result_nodes 10 🙂 289 ⛔ 22 ⛔ 30.52% 😞 Try splitting into smaller methods. Extract out complex expressions
src/sphinxcontrib/bibtex/domain.py BibtexDomain.env_updated 15 🙂 165 😞 16 ⛔ 38.35% 😞 Try splitting into smaller methods. Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants