Conversation
| 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): |
There was a problem hiding this comment.
Function main refactored with the following changes:
- Replace interpolated string formatting with f-string [×2] (
replace-interpolation-with-fstring) - Use named expression to simplify assignment and conditional (
use-named-expression)
| 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}] |
There was a problem hiding this comment.
Function main refactored with the following changes:
- Merge append into list declaration [×2] (
merge-list-append) - Move assignment closer to its usage within a block (
move-assign-in-block) - Replace a for append loop with list extend [×2] (
for-append-to-extend) - Use named expression to simplify assignment and conditional (
use-named-expression) - Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| 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) |
There was a problem hiding this comment.
Function Reader.__next__ refactored with the following changes:
- Simplify logical expression using De Morgan identities [×2] (
de-morgan) - Replace interpolated string formatting with f-string [×2] (
replace-interpolation-with-fstring) - Merge nested if conditions (
merge-nested-ifs)
| 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]) |
There was a problem hiding this comment.
Function main refactored with the following changes:
- Replace m.group(x) with m[x] for re.Match objects (
use-getitem-for-re-match-groups) - Replace interpolated string formatting with f-string [×3] (
replace-interpolation-with-fstring) - Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| 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')): |
There was a problem hiding this comment.
Function split_into_words refactored with the following changes:
- Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation)
|
|
||
| def is_letter(text): | ||
| return all([liblouis.isLetter(c) for c in text]) | ||
| return all(liblouis.isLetter(c) for c in text) |
There was a problem hiding this comment.
Function is_letter refactored with the following changes:
- Replace unneeded comprehension with generator (
comprehension-to-generator)
| 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] |
There was a problem hiding this comment.
Function translate refactored with the following changes:
- Replace a[0:x] with a[:x] and a[x:len(a)] with a[x:] (
remove-redundant-slice-index)
| 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 | ||
| ) |
There was a problem hiding this comment.
Function get_rule refactored with the following changes:
- Swap if/else branches of if expression to remove negation (
swap-if-expression) - Lift code into else after jump in control flow (
reintroduce-else) - Replace if statement with if expression (
assign-if-exp)
| hyphen_string = hyphen_string[1:len(hyphen_string)-1] | ||
| hyphen_string = hyphen_string[1:-1] |
There was a problem hiding this comment.
Function suggest_chunks refactored with the following changes:
- Simplify accessing last index of list (
simplify-negative-index)
| for i in range(0, max_rules): | ||
| for i in range(max_rules): |
There was a problem hiding this comment.
Function find_relevant_rules refactored with the following changes:
- Replace range(0, x) with range(x) (
remove-zero-from-range)
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 0.63%.
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!