Refactor change.py
This commit is contained in:
parent
d80081c214
commit
b0dfd43495
@ -80,13 +80,10 @@ def apply(
|
|||||||
changes = [changes]
|
changes = [changes]
|
||||||
|
|
||||||
return_str = isinstance(strings, str)
|
return_str = isinstance(strings, str)
|
||||||
if isinstance(strings, str):
|
strings = [strings] if isinstance(strings, str) else strings.copy()
|
||||||
strings = [strings]
|
|
||||||
else:
|
|
||||||
strings = strings.copy()
|
|
||||||
|
|
||||||
for change in changes:
|
for change in changes:
|
||||||
if is_valid_change(change, ignore_errors=ignore_errors) == False:
|
if not is_valid_change(change, ignore_errors=ignore_errors):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
change = reformat_change_to_regex(change, categories=categories, zero_characters=zero_characters)
|
change = reformat_change_to_regex(change, categories=categories, zero_characters=zero_characters)
|
||||||
@ -114,7 +111,7 @@ def is_valid_change(change, ignore_errors=True):
|
|||||||
|
|
||||||
valid = re.search(r'^[^>_/]+?>[^>_/]*?/?(:?[^>_/]*?_+[^>_/]*)?$', change)
|
valid = re.search(r'^[^>_/]+?>[^>_/]*?/?(:?[^>_/]*?_+[^>_/]*)?$', change)
|
||||||
if ignore_errors:
|
if ignore_errors:
|
||||||
return valid != None
|
return valid is not None
|
||||||
if not valid:
|
if not valid:
|
||||||
raise ValueError(f"Change {change} is not a valid sound change.")
|
raise ValueError(f"Change {change} is not a valid sound change.")
|
||||||
return True
|
return True
|
||||||
@ -167,10 +164,7 @@ def split_change(change):
|
|||||||
environment = re.sub('_+', '_', environment)
|
environment = re.sub('_+', '_', environment)
|
||||||
|
|
||||||
original, change_to = change.split('>')
|
original, change_to = change.split('>')
|
||||||
if '_' in environment:
|
before, after = environment.split('_') if '_' in environment else ('', '')
|
||||||
before, after = environment.split('_')
|
|
||||||
else:
|
|
||||||
before = after = ''
|
|
||||||
|
|
||||||
return (original, change_to, before, after)
|
return (original, change_to, before, after)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user