-
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
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.
Sourcery timed out performing refactorings.
Due to GitHub API limits, only the first 60 comments can be shown.
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}'") |
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 BeautifulSoup.__init__
refactored with the following changes:
- Simplify sequence length comparison (
simplify-len-comparison
) - Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
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) |
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 BeautifulSoup.endData
refactored with the following changes:
- Add guard clause (
last-if-guard
) - Replaces an empty collection equality with a boolean operation (
simplify-empty-collection-comparison
) - Replace list(), dict() or set() with comprehension (
collection-builtin-to-comprehension
) - Replace unneeded comprehension with generator (
comprehension-to-generator
) - Replace if statement with if expression (
assign-if-exp
)
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): |
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 BeautifulSoup._popToTag
refactored with the following changes:
- Move assignment closer to its usage within a block (
move-assign-in-block
) - Replace unused for index with underscore (
for-index-underscore
) - Replace range(0, x) with range(x) (
remove-zero-from-range
) - Use the built-in function
next
instead of a for-loop (use-next
)
# 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 |
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 BeautifulSoup.decode
refactored with the following changes:
- Move setting of default value for variable into
else
branch (introduce-default-else
) - Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
) - Replace if statement with if expression (
assign-if-exp
) - Swap if/else branches of if expression to remove negation (
swap-if-expression
) - Swap if/else branches (
swap-if-else-branches
) - Use x is None rather than x == None (
none-compare
)
This removes the following comments ( why? ):
# Print the XML declaration
re_definition = "[%s]" % "".join(characters_for_re) | ||
re_definition = f'[{"".join(characters_for_re)}]' |
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 EntitySubstitution._populate_class_variables
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
found = strainer.search(i) | ||
if found: | ||
if found := strainer.search(i): |
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 PageElement._find_all
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
)
if isinstance(value, list) or isinstance(value, tuple): | ||
if isinstance(value, (list, tuple)): |
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 PageElement._attr_value_as_string
refactored with the following changes:
- Merge isinstance calls (
merge-isinstance
)
return (attribute_value == value or attribute_value.startswith( | ||
value + '-')) | ||
return attribute_value == value or attribute_value.startswith(f'{value}-') | ||
|
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 PageElement._attribute_checker
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
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 | ||
|
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 PageElement.select
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
) - Swap if/else branches of if expression to remove negation (
swap-if-expression
)
"'%s' object has no attribute '%s'" % ( | ||
self.__class__.__name__, attr)) | ||
f"'{self.__class__.__name__}' object has no attribute '{attr}'" | ||
) |
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 NavigableString.__getattr__
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 0.20%.
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!