Skip to content

Comments

Sourcery refactored master branch#1

Open
sourcery-ai[bot] wants to merge 1 commit intomasterfrom
sourcery/master
Open

Sourcery refactored master branch#1
sourcery-ai[bot] wants to merge 1 commit intomasterfrom
sourcery/master

Conversation

@sourcery-ai
Copy link

@sourcery-ai sourcery-ai bot commented Jul 18, 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 Roshanson July 18, 2022 09:10
Comment on lines -38 to +46
printerrln('WARNING: word is too long to be processed, may be translated incorrectly: %s' % text)
printerrln(
f'WARNING: word is too long to be processed, may be translated incorrectly: {text}'
)

continue
if not is_letter(text):
printerrln('WARNING: word has non-letters: %s' % text)
printerrln(f'WARNING: word has non-letters: {text}')
continue
suggested_hyphen_string = suggest_chunks(text, braille)
if suggested_hyphen_string:
if suggested_hyphen_string := suggest_chunks(text, braille):
Copy link
Author

Choose a reason for hiding this comment

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

Function main refactored with the following changes:

Comment on lines -59 to +73
comments = []
comments.append("wrong braille\t\t" + actual_braille)
comments = ["wrong braille\t\t" + actual_braille]
suggest_rows = []
suggest_rules = []
non_letters = False
if not is_letter(text):
non_letters = True
comments.append("word has non-letters")
comments.append("applied rules")
applied_rules = [get_rule(x) for x in applied_rules if x is not None]
for rule in applied_rules:
comments.append("> " + "\t".join(rule))
other_relevant_rules = set(find_relevant_rules(text)) - set(applied_rules)
if other_relevant_rules:
comments.extend("> " + "\t".join(rule) for rule in applied_rules)
if other_relevant_rules := set(
find_relevant_rules(text)
) - set(applied_rules):
comments.append("other relevant rules")
for rule in other_relevant_rules:
comments.append("> " + "\t".join(rule))
suggest_rules.append({"opcode": "word", "text": text, "braille": braille})
comments.extend("> " + "\t".join(rule) for rule in other_relevant_rules)
suggest_rules = [{"opcode": "word", "text": text, "braille": braille}]
Copy link
Author

Choose a reason for hiding this comment

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

Function main refactored with the following changes:

Comment on lines -36 to +48
if not len(row) == 3:
printerrln('expected 3 columns, got %s: %s' % (len(row),row))
if len(row) != 3:
printerrln(f'expected 3 columns, got {len(row)}: {row}')
exit(1)
if not row[0] == "":
if row[0] != "":
printerrln("expected first column to be empty, got '%s'" % (row[0],))
exit(1)
maybe_chunked_text, braille = row[1:3]
maybe_chunked_text = to_lowercase(maybe_chunked_text)
text, chunked_text = read_text(maybe_chunked_text)
braille = braille if braille != "" else None
if braille != None:
if '0' in to_dot_pattern(braille).split('-'):
printerrln('invalid braille: %s' % (braille,))
exit(1)
if braille != None and '0' in to_dot_pattern(braille).split('-'):
printerrln(f'invalid braille: {braille}')
exit(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 Reader.__next__ refactored with the following changes:

for line in fileinput.FileInput(args.CONTRACTION_TABLE, openhook=fileinput.hook_encoded("utf-8")):
m = p.match(line)
exit_if_not(m and not m.group(1))
exit_if_not(m and not m[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 main refactored with the following changes:

word = []
word_hyphen_string = []
for c,(h1,h2) in izip(text, pairwise('1' + hyphen_string + '1')):
for c,(h1,h2) in izip(text, pairwise(f'1{hyphen_string}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 split_into_words refactored with the following changes:


def is_letter(text):
return all([liblouis.isLetter(c) for c in text])
return all(liblouis.isLetter(c) for c in text)
Copy link
Author

Choose a reason for hiding this comment

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

Function is_letter refactored with the following changes:

exit_if_not(liblouis._lou_translateWithTracing(table, c_text, byref(c_text_len), c_braille, byref(c_braille_len),
None, None, None, None, None, 0, c_rules, byref(c_rules_len)))
return c_braille.value, c_rules[0:c_rules_len.value]
return c_braille.value, c_rules[:c_rules_len.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 translate refactored with the following changes:

Comment on lines -174 to +178
if not liblouis.printRule(cast(c_rule_pointer, c_void_p), c_rule_string):
return None
return tuple(c_rule_string.value.split(" "))
return (
tuple(c_rule_string.value.split(" "))
if liblouis.printRule(cast(c_rule_pointer, c_void_p), c_rule_string)
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 get_rule refactored with the following changes:

Comment on lines -185 to +187
hyphen_string = hyphen_string[1:len(hyphen_string)-1]
hyphen_string = hyphen_string[1:-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 suggest_chunks refactored with the following changes:

Comment on lines -193 to +195
for i in range(0, max_rules):
for i in range(max_rules):
Copy link
Author

Choose a reason for hiding this comment

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

Function find_relevant_rules refactored with the following changes:

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Jul 18, 2022

Sourcery Code Quality Report

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

Quality metrics Before After Change
Complexity 21.40 😞 18.79 😞 -2.61 👍
Method Length 54.70 ⭐ 54.64 ⭐ -0.06 👍
Working memory 9.81 🙂 9.79 🙂 -0.02 👍
Quality 54.91% 🙂 55.54% 🙂 0.63% 👍
Other metrics Before After Change
Lines 405 411 6
Changed files Quality Before Quality After Quality Change
tools/lou_maketable.d/export_chunked_words.py 32.41% 😞 31.42% 😞 -0.99% 👎
tools/lou_maketable.d/make_suggestions.py 17.75% ⛔ 19.34% ⛔ 1.59% 👍
tools/lou_maketable.d/submit_rows.py 70.23% 🙂 70.91% 🙂 0.68% 👍
tools/lou_maketable.d/submit_rules.py 29.01% 😞 28.76% 😞 -0.25% 👎
tools/lou_maketable.d/utils.py 78.11% ⭐ 77.89% ⭐ -0.22% 👎

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

File Function Complexity Length Working Memory Quality Recommendation
tools/lou_maketable.d/make_suggestions.py main 59 ⛔ 367 ⛔ 18 ⛔ 9.25% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
tools/lou_maketable.d/export_chunked_words.py main 38 ⛔ 177 😞 15 😞 25.27% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
tools/lou_maketable.d/submit_rules.py main 26 😞 329 ⛔ 13 😞 25.41% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
tools/lou_maketable.d/utils.py split_into_words 11 🙂 138 😞 11 😞 51.72% 🙂 Try splitting into smaller methods. Extract out complex expressions
tools/lou_maketable.d/utils.py compare_chunks 10 🙂 89 🙂 12 😞 57.20% 🙂 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