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 master branch #22
Conversation
f80c0b6
to
641f5b7
Compare
| kw.update({'yscrollcommand': self.vbar.set}) | ||
| kw['yscrollcommand'] = self.vbar.set |
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 _ScrolledText.__init__ refactored with the following changes:
- Add single value to dictionary directly rather than using update() (
simplify-dictionary-update)
| if not 'wrap' in kwargs.keys(): | ||
| if 'wrap' not in kwargs.keys(): | ||
| self.config(wrap='word') | ||
| if not 'background' in kwargs.keys(): | ||
| if 'background' not in kwargs.keys(): |
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 HTMLScrolledText._w_init refactored with the following changes:
- Simplify logical expression using De Morgan identities [×2] (
de-morgan)
| if not 'background' in kwargs.keys(): | ||
| if 'background' not in kwargs.keys(): | ||
| if sys.platform.startswith('win'): | ||
| self.config(background='SystemButtonFace') | ||
| else: | ||
| self.config(background='#d9d9d9') | ||
|
|
||
| if not 'borderwidth' in kwargs.keys(): | ||
| if 'borderwidth' not in kwargs.keys(): | ||
| self.config(borderwidth=0) | ||
|
|
||
| if not 'padx' in kwargs.keys(): | ||
| if 'padx' not in kwargs.keys(): |
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 HTMLLabel._w_init refactored with the following changes:
- Simplify logical expression using De Morgan identities [×3] (
de-morgan)
| #------------------------------------------------------------------------------------------ | ||
| if self.ordered: | ||
| if self.type == HTML.TypeOrderedList._1: | ||
| return str(self.index) | ||
| elif self.type == HTML.TypeOrderedList.a: | ||
| return self._index_to_str(self.index).lower() | ||
| elif self.type == HTML.TypeOrderedList.A: | ||
| return self._index_to_str(self.index).upper() | ||
| else: | ||
| if not self.ordered: | ||
| return chr(8226) | ||
| if self.type == HTML.TypeOrderedList._1: | ||
| return str(self.index) | ||
| elif self.type == HTML.TypeOrderedList.a: | ||
| return self._index_to_str(self.index).lower() | ||
| elif self.type == HTML.TypeOrderedList.A: | ||
| return self._index_to_str(self.index).upper() |
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 ListTag.line_index refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches) - Remove unnecessary else after guard condition (
remove-unnecessary-else)
This removes the following comments ( why? ):
#------------------------------------------------------------------------------------------
|
|
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.
Found the following improvement in Function HTMLTextParser._stack_pop:
| elif tag == HTML.Tag.I or tag == HTML.Tag.EM: | ||
| elif tag in [HTML.Tag.I, HTML.Tag.EM]: |
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 HTMLTextParser.handle_starttag refactored with the following changes:
- Replace multiple comparisons of same variable with
inoperator (merge-comparisons) - Use named expression to simplify assignment and conditional (
use-named-expression) - Hoist conditional out of nested conditional (
hoist-if-from-if)
This removes the following comments ( why? ):
#------------------------------------------------------------------ [ LISTS_LINES ]
| elif double: | ||
| self._w.insert(tk.INSERT, "\n\n") | ||
| else: | ||
| if double: | ||
| self._w.insert(tk.INSERT, "\n\n") | ||
| else: | ||
| self._w.insert(tk.INSERT, "\n") | ||
| self._w.insert(tk.INSERT, "\n") |
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 HTMLTextParser._insert_new_line refactored with the following changes:
- Merge else clause's nested if statement into elif (
merge-else-if-into-elif)
| #------------------------------------------------------------------------------------------ | ||
| if self.strip: | ||
| if len(self.html_tags) and self.html_tags[-1] in (HTML.Tag.PRE, HTML.Tag.CODE): | ||
| pass | ||
| elif not data.strip(): | ||
| if len(self.html_tags) and self.html_tags[-1] in (HTML.Tag.PRE, HTML.Tag.CODE): | ||
| pass | ||
| elif not data.strip(): | ||
| if self.strip: | ||
| data = "" | ||
| else: | ||
| # left strip | ||
| if self._w.index("end-1c").endswith(".0"): | ||
| data = data.lstrip() | ||
| elif self._w.get("end-2c", "end-1c") == " ": | ||
| data = data.lstrip() | ||
|
|
||
| data = data.replace("\n", " ").replace("\t", " ") | ||
| data = data + " " | ||
| data = self._remove_multi_spaces(data) | ||
| if len(self.html_tags): | ||
| level = len(self.list_tags) | ||
| if self.html_tags[-1] in (HTML.Tag.UL, HTML.Tag.OL): | ||
| self._w.insert(tk.INSERT, "\t" * 2 * level) | ||
| elif self.strip: | ||
| # left strip | ||
| if self._w.index("end-1c").endswith(".0"): | ||
| data = data.lstrip() | ||
| elif self._w.get("end-2c", "end-1c") == " ": | ||
| data = data.lstrip() | ||
|
|
||
| data = data.replace("\n", " ").replace("\t", " ") | ||
| data = f"{data} " | ||
| data = self._remove_multi_spaces(data) | ||
| if len(self.html_tags) and self.html_tags[-1] in ( | ||
| HTML.Tag.UL, | ||
| HTML.Tag.OL, | ||
| ): | ||
| level = len(self.list_tags) | ||
| self._w.insert(tk.INSERT, "\t" * 2 * level) |
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 HTMLTextParser.handle_data refactored with the following changes:
- Swap positions of nested conditionals (
swap-nested-ifs) - Merge else clause's nested if statement into elif (
merge-else-if-into-elif) - Use f-string instead of string concatenation (
use-fstring-for-concatenation) - Merge nested if conditions (
merge-nested-ifs) - Move assignments closer to their usage (
move-assign) - Remove redundant conditional (
remove-redundant-if)
This removes the following comments ( why? ):
#------------------------------------------------------------------------------------------
| elif tag == HTML.Tag.I or tag == HTML.Tag.EM: | ||
| elif tag in [HTML.Tag.I, HTML.Tag.EM]: | ||
| self._stack_pop(tag, Fnt.SLANT) | ||
|
|
||
| elif tag == HTML.Tag.A: | ||
| self._stack_pop(tag, Bind.LINK) | ||
|
|
||
| elif tag == HTML.Tag.OL or tag == HTML.Tag.UL: | ||
| elif tag in [HTML.Tag.OL, HTML.Tag.UL]: |
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 HTMLTextParser.handle_endtag refactored with the following changes:
- Replace multiple comparisons of same variable with
inoperator [×2] (merge-comparisons)
| return "<%s: %s>" % (self.__class__.__name__, self._file) | ||
| return f"<{self.__class__.__name__}: {self._file}>" |
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 RenderHTML.__repr__ 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.79%.
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
masterrefactored 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
masterbranch, then run:Help us improve this pull request!