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 master branch #15

Closed
wants to merge 1 commit into from
Closed

Conversation

sourcery-ai[bot]
Copy link

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

Branch master 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 master branch, then run:

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

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from bauripalash March 10, 2022 11:17
Comment on lines -52 to +54
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():
Copy link
Author

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 (de-morgan)

Comment on lines -113 to +122
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():
Copy link
Author

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 (de-morgan)

Comment on lines -225 to +232
#------------------------------------------------------------------------------------------
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()
Copy link
Author

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:

This removes the following comments ( why? ):

#------------------------------------------------------------------------------------------

Comment on lines +414 to +422
elif tag == HTML.Tag.A and attrs[HTML.Attrs.HREF]:
self._stack_add(tag, Fnt.UNDERLINE, True)
self._stack_add(tag, Fnt.OVERSTRIKE, False)
elif tag == HTML.Tag.U:
self._stack_add(tag, Fnt.UNDERLINE, True)
self._stack_add(tag, Fnt.OVERSTRIKE, False)
else:
if tag == HTML.Tag.A and attrs[HTML.Attrs.HREF]:
self._stack_add(tag, Fnt.UNDERLINE, True)
self._stack_add(tag, Fnt.OVERSTRIKE, False)
elif tag == HTML.Tag.U:
self._stack_add(tag, Fnt.UNDERLINE, True)
self._stack_add(tag, Fnt.OVERSTRIKE, False)
else:
self._stack_add(tag, Fnt.UNDERLINE)
self._stack_add(tag, Fnt.OVERSTRIKE)
self._stack_add(tag, Fnt.UNDERLINE)
self._stack_add(tag, Fnt.OVERSTRIKE)
Copy link
Author

Choose a reason for hiding this comment

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

Function HTMLTextParser._parse_styles refactored with the following changes:

Comment on lines -440 to +437
elif tag == HTML.Tag.I or tag == HTML.Tag.EM:
elif tag in [HTML.Tag.I, HTML.Tag.EM]:
Copy link
Author

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:

This removes the following comments ( why? ):

#------------------------------------------------------------------ [ LISTS_LINES ]

Comment on lines +559 to +562
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")
Copy link
Author

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:

Comment on lines -593 to +607
#------------------------------------------------------------------------------------------
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)
Copy link
Author

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:

This removes the following comments ( why? ):

#------------------------------------------------------------------------------------------

Comment on lines -640 to +641
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]:
Copy link
Author

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:

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Mar 10, 2022

Sourcery Code Quality Report

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

Quality metrics Before After Change
Complexity 21.08 😞 19.69 😞 -1.39 👍
Method Length 86.31 🙂 86.13 🙂 -0.18 👍
Working memory 11.48 😞 11.14 😞 -0.34 👍
Quality 50.41% 🙂 51.24% 🙂 0.83% 👍
Other metrics Before After Change
Lines 737 732 -5
Changed files Quality Before Quality After Quality Change
tkhtmlview/init.py 78.35% ⭐ 78.46% ⭐ 0.11% 👍
tkhtmlview/html_parser.py 45.90% 😞 46.80% 😞 0.90% 👍

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

File Function Complexity Length Working Memory Quality Recommendation
tkhtmlview/html_parser.py HTMLTextParser.handle_starttag 72 ⛔ 647 ⛔ 22 ⛔ 4.03% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
tkhtmlview/html_parser.py HTMLTextParser._parse_styles 41 ⛔ 557 ⛔ 14 😞 15.31% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
tkhtmlview/html_parser.py HTMLTextParser.handle_endtag 21 😞 228 ⛔ 12 😞 34.27% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
tkhtmlview/html_parser.py HTMLTextParser.handle_data 12 🙂 133 😞 13 😞 48.10% 😞 Try splitting into smaller methods. Extract out complex expressions
tkhtmlview/html_parser.py HTMLTextParser._parse_attrs 11 🙂 116 🙂 12 😞 52.64% 🙂 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.

None yet

1 participant