-
Notifications
You must be signed in to change notification settings - Fork 31
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 #2758
base: main
Are you sure you want to change the base?
Conversation
if __name__ == '__main__': | ||
bottle.run(addr=args.addr, port=args.port) | ||
if __name__ == '__main__': | ||
bottle.run(addr=args.addr, port=args.port) |
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.
Lines 89-90
refactored with the following changes:
- Hoist conditional out of nested conditional (
hoist-if-from-if
)
key = os.environ.get('PUBLISHABLE_KEY') | ||
if key: | ||
if key := os.environ.get('PUBLISHABLE_KEY'): |
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 StripePublicKey.get
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
)
hits = db.aql.execute( | ||
if hits := db.aql.execute( |
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 Redirect.get
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
)
if ( | ||
num_start <= doc['num_end'] | ||
and num_end >= doc['num_start'] | ||
or doc['num_start'] <= num_end | ||
and doc['num_end'] >= num_start | ||
): | ||
if num_start <= doc['num_end'] and num_end >= doc['num_start']: |
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 UidMatcher.range_query
refactored with the following changes:
- Remove redundant conditional (
remove-redundant-if
)
if lang['lang'] == original_lang: | ||
result = '11111' # So that root language is always first. | ||
else: | ||
result = lang['lang'] | ||
if lang['segmented']: | ||
result += '_0' | ||
else: | ||
result += '_1' | ||
result = '11111' if lang['lang'] == original_lang else lang['lang'] | ||
result += '_0' if lang['segmented'] else '_1' |
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 language_sort
refactored with the following changes:
- Replace if statement with if expression [×2] (
assign-if-exp
)
This removes the following comments ( why? ):
# So that root language is always first.
if x['type'] == 'full' and x['resembling']: | ||
p_type = 'resembling' | ||
else: | ||
p_type = x['type'] | ||
p_type = 'resembling' if x['type'] == 'full' and x['resembling'] else x['type'] |
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 sort_parallels_type_key
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
r = list(itertools.islice(iterator, 0, chunk_size)) | ||
if r: | ||
if r := list(itertools.islice(iterator, 0, chunk_size)): |
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 chunks
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
)
(f'dn', 'an', 'sa', 'sa-2'), | ||
('dn', 'an', 'sa', 'sa-2'), |
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.
Lines 34-34
refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring
)
m = regex.search('[0-9]+$', from_uid) | ||
if m: | ||
from_nr = int(m[0]) | ||
else: | ||
from_nr = 0 | ||
from_nr = int(m[0]) if (m := regex.search('[0-9]+$', from_uid)) else 0 |
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 generate_relationship_edges
refactored with the following changes:
- Use named expression to simplify assignment and conditional [×3] (
use-named-expression
) - Replace if statement with if expression [×3] (
assign-if-exp
)
name_data = [] | ||
for entry in data: | ||
name_data.append( | ||
{ | ||
'name': entry.pop('name'), | ||
'symbol': entry['symbol'], | ||
'lang': 'en', | ||
'_key': f'{entry["symbol"]}_en', | ||
} | ||
) | ||
name_data = [ | ||
{ | ||
'name': entry.pop('name'), | ||
'symbol': entry['symbol'], | ||
'lang': 'en', | ||
'_key': f'{entry["symbol"]}_en', | ||
} | ||
for entry in data | ||
] |
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 load_currencies
refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension
)
for item in content: | ||
docs.append({ | ||
docs.extend( | ||
{ | ||
'from': from_lang, | ||
'to': to_lang, | ||
'dictname': dict_name, | ||
**item, | ||
}) | ||
|
||
} | ||
for item in content | ||
) |
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 load_simple_dictionaries
refactored with the following changes:
- Replace a for append loop with list extend (
for-append-to-extend
)
if lang == 'en': | ||
return 'a', uid | ||
else: | ||
return lang, uid | ||
return ('a', uid) if lang == 'en' else (lang, uid) |
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 sort_key
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
|
||
updates = [] | ||
num_en = num_strings_by_lang['en'] | ||
|
||
for iso_code, count in num_strings_by_lang.items(): | ||
updates.append( | ||
{ | ||
'_key': iso_code, | ||
'localized': True, | ||
'localized_percent': int(100 * count / num_en), | ||
} | ||
) | ||
num_en = num_strings_by_lang['en'] | ||
|
||
updates = [ | ||
{ | ||
'_key': iso_code, | ||
'localized': True, | ||
'localized_percent': int(100 * count / num_en), | ||
} | ||
for iso_code, count in num_strings_by_lang.items() | ||
] |
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 _update_languages
refactored with the following changes:
- Move assignment closer to its usage within a block (
move-assign-in-block
) - Convert for loop into list comprehension (
list-comprehension
)
e = root.select_one('.publication-date') | ||
if e: | ||
if e := root.select_one('.publication-date'): |
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 TextInfoModel._get_publication_date
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
)
return right_side.text_content() + ' (' + left_side.text_content() + ')' | ||
return f'{right_side.text_content()} ({left_side.text_content()})' |
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 TextInfoModel._get_name
refactored with the following changes:
- Use f-string instead of string concatenation [×3] (
use-fstring-for-concatenation
)
return '{}'.format(e.attrib['id']).replace('t', 'T ') | ||
return f"{e.attrib['id']}".replace('t', 'T ') |
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 TextInfoModel._get_volpage
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
match = regex.fullmatch(r'ms(\d+[A-Z][a-z]*\d*)_(\d+)', ref) | ||
if match: | ||
if match := regex.fullmatch(r'ms(\d+[A-Z][a-z]*\d*)_(\d+)', ref): | ||
msbook, msnum = match.groups() | ||
ms.append((msbook.lower(), int(msnum))) | ||
continue | ||
|
||
match = regex.fullmatch(r'(pts-vp-pli(?:[12]ed)?)(?:(\d+)\.)?(\d+)', ref) | ||
if match: | ||
if match := regex.fullmatch( | ||
r'(pts-vp-pli(?:[12]ed)?)(?:(\d+)\.)?(\d+)', ref | ||
): | ||
pts_edition, vol, page = match.groups() | ||
if pts_edition == 'pts-vp-pli': | ||
pts_edition = 'pts-vp-pli1ed' | ||
pts.append((pts_edition, vol, int(page))) | ||
continue | ||
|
||
match = regex.fullmatch(r'vnp(\d+)', ref) | ||
if match: | ||
if match := regex.fullmatch(r'vnp(\d+)', ref): |
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 PaliPageNumbinator.load
refactored with the following changes:
- Use named expression to simplify assignment and conditional [×3] (
use-named-expression
)
# filter out base class from results and get class object | ||
migration_class = [ | ||
return [ | ||
migration_cls | ||
for migration_cls in migration_classes | ||
if migration_cls[0] != 'Migration' | ||
][0][1] | ||
return migration_class |
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 _import_migration_class
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
This removes the following comments ( why? ):
# filter out base class from results and get class object
assert len(paths) != 0 | ||
assert paths |
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 test_run_migrations_and_class_import
refactored with the following changes:
- Simplify sequence length comparison (
simplify-len-comparison
)
result = [] | ||
sentence_list = re.split(r'[.!?...]+', input_string) | ||
for sentence in sentence_list: | ||
if keyword in sentence: | ||
result.append(sentence.strip()) | ||
|
||
return result | ||
return [sentence.strip() for sentence in sentence_list if keyword in sentence] |
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 find_sentences_with_keyword
refactored with the following changes:
- Move assignment closer to its usage within a block (
move-assign-in-block
) - Convert for loop into list comprehension (
list-comprehension
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
)
possible_uids = [] | ||
name_exclude_sutta = name | ||
if 'sutta' in name: | ||
name_exclude_sutta = name.replace('sutta', '').strip() | ||
|
||
possible_uids.extend(list(db.aql.execute(POSSIBLE_SUTTA_BY_NAME, bind_vars={'name': name_exclude_sutta}))) | ||
possible_uids = list( | ||
list( | ||
db.aql.execute( | ||
POSSIBLE_SUTTA_BY_NAME, bind_vars={'name': name_exclude_sutta} | ||
) | ||
) | ||
) |
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 fetch_suttaplexs_by_name
refactored with the following changes:
- Move assignment closer to its usage within a block (
move-assign-in-block
) - Merge extend into list declaration (
merge-list-extend
)
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:Help us improve this pull request!