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 20, 2023

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 therealcorwin March 20, 2023 13:23
Copy link
Author

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sourcery timed out performing refactorings.

Due to GitHub API limits, only the first 60 comments can be shown.

Comment on lines -140 to +142
if len(kwargs) > 0:
if kwargs:
arg = kwargs.keys().pop()
raise TypeError(
"__init__() got an unexpected keyword argument '%s'" % arg)
raise TypeError(f"__init__() got an unexpected keyword argument '{arg}'")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function BeautifulSoup.__init__ refactored with the following changes:

Comment on lines -231 to +243
if self.currentData:
currentData = u''.join(self.currentData)
if (currentData.translate(self.STRIP_ASCII_SPACES) == '' and
not set([tag.name for tag in self.tagStack]).intersection(
self.builder.preserve_whitespace_tags)):
if '\n' in currentData:
currentData = '\n'
else:
currentData = ' '
self.currentData = []
if self.parse_only and len(self.tagStack) <= 1 and \
if not self.currentData:
return
currentData = u''.join(self.currentData)
if not currentData.translate(self.STRIP_ASCII_SPACES) and not {
tag.name for tag in self.tagStack
}.intersection(self.builder.preserve_whitespace_tags):
currentData = '\n' if '\n' in currentData else ' '
self.currentData = []
if self.parse_only and len(self.tagStack) <= 1 and \
(not self.parse_only.text or \
not self.parse_only.search(currentData)):
return
o = containerClass(currentData)
self.object_was_parsed(o)
return
o = containerClass(currentData)
self.object_was_parsed(o)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function BeautifulSoup.endData refactored with the following changes:

Comment on lines -265 to +278
numPops = 0
mostRecentTag = None

for i in range(len(self.tagStack) - 1, 0, -1):
if (name == self.tagStack[i].name
and nsprefix == self.tagStack[i].prefix):
numPops = len(self.tagStack) - i
break
numPops = next(
(
len(self.tagStack) - i
for i in range(len(self.tagStack) - 1, 0, -1)
if (
name == self.tagStack[i].name
and nsprefix == self.tagStack[i].prefix
)
),
0,
)
if not inclusivePop:
numPops = numPops - 1

for i in range(0, numPops):
for _ in range(numPops):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function BeautifulSoup._popToTag refactored with the following changes:

Comment on lines -322 to +331
# Print the XML declaration
encoding_part = ''
if eventual_encoding != None:
encoding_part = ' encoding="%s"' % eventual_encoding
if eventual_encoding is None:
encoding_part = ''
else:
encoding_part = f' encoding="{eventual_encoding}"'
prefix = u'<?xml version="1.0"%s?>\n' % encoding_part
else:
prefix = u''
if not pretty_print:
indent_level = None
else:
indent_level = 0
indent_level = 0 if pretty_print else None
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function BeautifulSoup.decode refactored with the following changes:

This removes the following comments ( why? ):

# Print the XML declaration

re_definition = "[%s]" % "".join(characters_for_re)
re_definition = f'[{"".join(characters_for_re)}]'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function EntitySubstitution._populate_class_variables refactored with the following changes:

Comment on lines -427 to +412
found = strainer.search(i)
if found:
if found := strainer.search(i):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function PageElement._find_all refactored with the following changes:

Comment on lines -494 to +478
if isinstance(value, list) or isinstance(value, tuple):
if isinstance(value, (list, tuple)):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function PageElement._attr_value_as_string refactored with the following changes:

Comment on lines -533 to +518
return (attribute_value == value or attribute_value.startswith(
value + '-'))
return attribute_value == value or attribute_value.startswith(f'{value}-')

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function PageElement._attribute_checker refactored with the following changes:

Comment on lines -583 to +568
if not tag.has_attr('class'):
return False
return classes.issubset(tag['class'])
return classes.issubset(tag['class']) if tag.has_attr('class') else False

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function PageElement.select refactored with the following changes:

Comment on lines -666 to +650
"'%s' object has no attribute '%s'" % (
self.__class__.__name__, attr))
f"'{self.__class__.__name__}' object has no attribute '{attr}'"
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function NavigableString.__getattr__ refactored with the following changes:

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Mar 20, 2023

Sourcery Code Quality Report

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

Quality metrics Before After Change
Complexity 53.46 ⛔ 53.98 ⛔ 0.52 👎
Method Length 70.50 🙂 70.26 🙂 -0.24 👍
Working memory 8.32 🙂 8.38 🙂 0.06 👎
Quality 56.90% 🙂 57.10% 🙂 0.20% 👍
Other metrics Before After Change
Lines 29222 28729 -493
Changed files Quality Before Quality After Quality Change
bs4/__init__.py 61.63% 🙂 62.08% 🙂 0.45% 👍
bs4/dammit.py 50.51% 🙂 50.77% 🙂 0.26% 👍
bs4/element.py 62.71% 🙂 63.36% 🙂 0.65% 👍
bs4/testing.py 92.83% ⭐ 92.89% ⭐ 0.06% 👍
bs4/builder/__init__.py 81.12% ⭐ 82.81% ⭐ 1.69% 👍
bs4/builder/_html5lib.py 85.86% ⭐ 86.60% ⭐ 0.74% 👍
bs4/builder/_htmlparser.py 58.88% 🙂 58.25% 🙂 -0.63% 👎
bs4/builder/_lxml.py 73.06% 🙂 73.40% 🙂 0.34% 👍
cherrypy/__init__.py 61.65% 🙂 62.62% 🙂 0.97% 👍
cherrypy/_cpchecker.py 53.82% 🙂 54.61% 🙂 0.79% 👍
cherrypy/_cpcompat.py 79.28% ⭐ 78.52% ⭐ -0.76% 👎
cherrypy/_cpconfig.py 63.07% 🙂 62.90% 🙂 -0.17% 👎
cherrypy/_cpdispatch.py 34.54% 😞 36.09% 😞 1.55% 👍
cherrypy/_cperror.py 67.34% 🙂 67.72% 🙂 0.38% 👍
cherrypy/_cplogging.py 71.72% 🙂 71.39% 🙂 -0.33% 👎
cherrypy/_cpmodpy.py 40.58% 😞 40.85% 😞 0.27% 👍
cherrypy/_cpnative_server.py 35.79% 😞 36.53% 😞 0.74% 👍
cherrypy/_cpreqbody.py 53.22% 🙂 53.21% 🙂 -0.01% 👎
cherrypy/_cprequest.py 62.32% 🙂 63.50% 🙂 1.18% 👍
cherrypy/_cpserver.py 82.58% ⭐ 82.46% ⭐ -0.12% 👎
cherrypy/_cpthreadinglocal.py 75.20% ⭐ 75.23% ⭐ 0.03% 👍
cherrypy/_cptools.py 80.45% ⭐ 80.54% ⭐ 0.09% 👍
cherrypy/_cptree.py 68.70% 🙂 69.50% 🙂 0.80% 👍
cherrypy/_cpwsgi.py 64.82% 🙂 65.46% 🙂 0.64% 👍
cherrypy/cherryd 34.34% 😞 34.32% 😞 -0.02% 👎
cherrypy/lib/__init__.py 86.99% ⭐ 88.00% ⭐ 1.01% 👍
cherrypy/lib/auth_basic.py 61.13% 🙂 60.96% 🙂 -0.17% 👎
cherrypy/lib/auth_digest.py 62.02% 🙂 60.79% 🙂 -1.23% 👎
cherrypy/lib/caching.py 45.82% 😞 46.54% 😞 0.72% 👍
cherrypy/lib/covercp.py 65.94% 🙂 65.60% 🙂 -0.34% 👎
cherrypy/lib/cpstats.py 62.39% 🙂 62.05% 🙂 -0.34% 👎
cherrypy/lib/cptools.py 54.52% 🙂 55.06% 🙂 0.54% 👍
cherrypy/lib/encoding.py 33.52% 😞 33.65% 😞 0.13% 👍
cherrypy/lib/gctools.py 54.40% 🙂 55.58% 🙂 1.18% 👍
cherrypy/lib/httpauth.py 79.01% ⭐ 78.25% ⭐ -0.76% 👎
cherrypy/lib/httputil.py 77.09% ⭐ 77.26% ⭐ 0.17% 👍
cherrypy/lib/jsontools.py 74.35% 🙂 74.06% 🙂 -0.29% 👎
cherrypy/lib/profiler.py 81.30% ⭐ 81.41% ⭐ 0.11% 👍
cherrypy/lib/reprconf.py 82.99% ⭐ 83.44% ⭐ 0.45% 👍
cherrypy/lib/sessions.py 80.99% ⭐ 81.33% ⭐ 0.34% 👍
cherrypy/lib/static.py 35.38% 😞 35.94% 😞 0.56% 👍
cherrypy/process/plugins.py 71.51% 🙂 71.76% 🙂 0.25% 👍
cherrypy/process/servers.py 79.74% ⭐ 79.26% ⭐ -0.48% 👎
cherrypy/process/win32.py 86.01% ⭐ 86.01% ⭐ 0.00%
cherrypy/process/wspbus.py 76.31% ⭐ 76.73% ⭐ 0.42% 👍
cherrypy/scaffold/__init__.py 89.28% ⭐ 89.22% ⭐ -0.06% 👎
cherrypy/wsgiserver/ssl_builtin.py 78.33% ⭐ 78.15% ⭐ -0.18% 👎
cherrypy/wsgiserver/ssl_pyopenssl.py 77.25% ⭐ 77.52% ⭐ 0.27% 👍
cherrypy/wsgiserver/wsgiserver2.py 55.20% 🙂 55.66% 🙂 0.46% 👍
cherrypy/wsgiserver/wsgiserver3.py 61.64% 🙂 62.25% 🙂 0.61% 👍
headphones/__init__.py 55.85% 🙂 55.84% 🙂 -0.01% 👎
headphones/albumart.py 77.91% ⭐ 82.52% ⭐ 4.61% 👍
headphones/api.py 81.10% ⭐ 82.46% ⭐ 1.36% 👍
headphones/cache.py 61.96% 🙂 72.53% 🙂 10.57% 👍
headphones/classes.py 91.01% ⭐ 91.08% ⭐ 0.07% 👍
headphones/common.py 75.74% ⭐ 75.30% ⭐ -0.44% 👎
headphones/db.py 80.27% ⭐ 78.08% ⭐ -2.19% 👎
headphones/gks.py 42.86% 😞 49.48% 😞 6.62% 👍
headphones/helpers.py 77.25% ⭐ 77.79% ⭐ 0.54% 👍
headphones/importer.py 55.27% 🙂 56.14% 🙂 0.87% 👍
headphones/lastfm.py 52.30% 🙂 51.76% 🙂 -0.54% 👎
headphones/logger.py 77.89% ⭐ 77.85% ⭐ -0.04% 👎
headphones/mb.py 57.78% 🙂 57.70% 🙂 -0.08% 👎
headphones/notifiers.py 75.59% ⭐ 75.23% ⭐ -0.36% 👎
headphones/postprocessor.py 43.37% 😞 41.44% 😞 -1.93% 👎
headphones/searcher.py 42.98% 😞 43.63% 😞 0.65% 👍
headphones/searcher_rutracker.py 74.69% 🙂 75.78% ⭐ 1.09% 👍
headphones/t411.py 69.98% 🙂 70.07% 🙂 0.09% 👍
headphones/versioncheck.py 52.43% 🙂 52.19% 🙂 -0.24% 👎
headphones/webserve.py 59.01% 🙂 59.22% 🙂 0.21% 👍
html5lib/html5parser.py 7.21% ⛔ 6.83% ⛔ -0.38% 👎
html5lib/ihatexml.py 77.70% ⭐ 77.30% ⭐ -0.40% 👎
html5lib/inputstream.py 66.61% 🙂 66.78% 🙂 0.17% 👍
html5lib/sanitizer.py 27.70% 😞 27.22% 😞 -0.48% 👎
html5lib/tokenizer.py 55.22% 🙂 55.30% 🙂 0.08% 👍
html5lib/utils.py 89.56% ⭐ 89.81% ⭐ 0.25% 👍
html5lib/filters/formfiller.py 7.54% ⛔ 8.17% ⛔ 0.63% 👍
html5lib/filters/inject_meta_charset.py 18.65% ⛔ 18.61% ⛔ -0.04% 👎
html5lib/filters/lint.py 21.36% ⛔ 21.58% ⛔ 0.22% 👍
html5lib/filters/optionaltags.py 36.29% 😞 37.16% 😞 0.87% 👍

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

File Function Complexity Length Working Memory Quality Recommendation
html5lib/html5parser.py getPhases 527 ⛔ 12105 ⛔ 0.00% ⛔ Refactor to reduce nesting. Try splitting into smaller methods
html5lib/filters/formfiller.py SimpleFilter.__iter__ 114 ⛔ 496 ⛔ 23 ⛔ 3.20% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
cherrypy/lib/encoding.py gzip 86 ⛔ 337 ⛔ 21 ⛔ 6.36% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
bs4/element.py PageElement.select 53 ⛔ 323 ⛔ 8.18% ⛔ Refactor to reduce nesting. Try splitting into smaller methods
html5lib/html5parser.py HTMLParser.mainLoop 42 ⛔ 315 ⛔ 28 ⛔ 9.18% ⛔ Refactor to reduce nesting. 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