Skip to content

Commit fe64bac

Browse files
committed
Appease flake8
1 parent 210ced1 commit fe64bac

File tree

6 files changed

+37
-35
lines changed

6 files changed

+37
-35
lines changed

apertium_apy/apy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464

6565

6666
def sig_handler(sig, frame):
67-
global missing_freqs_db
67+
global missing_freqs_db # noqa: F824
6868
if missing_freqs_db is not None:
6969
if 'children' in frame.f_locals:
7070
for child in frame.f_locals['children']:

apertium_apy/handlers/billookup.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class BillookupHandler(BaseHandler):
1111
def get_pair_or_error(self, langpair):
1212
try:
1313
l1, l2 = map(to_alpha3_code, langpair.split('|'))
14-
in_mode = f"{l1}-{l2}"
14+
in_mode = f'{l1}-{l2}'
1515
except ValueError:
1616
self.send_error(400, explanation='That pair is invalid, use e.g. eng|spa')
1717
return None
@@ -25,7 +25,7 @@ def get_pair_or_error(self, langpair):
2525
@gen.coroutine
2626
def lookup_and_respond(self, pair, query):
2727
try:
28-
path, mode = self.billookup["-".join(pair)]
28+
path, mode = self.billookup['-'.join(pair)]
2929
formatting = 'none'
3030
commands = [['apertium', '-d', path, '-f', formatting, mode]]
3131
result = yield translate_simple(query, commands)
@@ -48,15 +48,15 @@ def lookup_and_respond(self, pair, query):
4848
# allowed subcategories per POS (to be filled out)
4949
# could separate this out in a language specific way
5050
allowed = {
51-
"n": ["m", "f", "nt", "aa", "nn"],
52-
"np": ["ant", "top", "cog", "m", "f", "nt", "mf", "aa", "nn"],
53-
"v": ["tv", "iv"],
54-
"vblex": [],
51+
'n': ['m', 'f', 'nt', 'aa', 'nn'],
52+
'np': ['ant', 'top', 'cog', 'm', 'f', 'nt', 'mf', 'aa', 'nn'],
53+
'v': ['tv', 'iv'],
54+
'vblex': [],
5555
}
5656

5757
def normalize(form):
58-
word = form.split("<", 1)[0]
59-
tags = re.findall(r"<([^>]+)>", form)
58+
word = form.split('<', 1)[0]
59+
tags = re.findall(r'<([^>]+)>', form)
6060
if not tags:
6161
return word, []
6262
pos = tags[0]
@@ -68,39 +68,39 @@ def normalize(form):
6868
if t not in filtered:
6969
filtered.append(t)
7070
else:
71-
tag_with_brackets = f"<{t}>"
71+
tag_with_brackets = f'<{t}>'
7272
if tag_with_brackets not in extra:
7373
extra.append(tag_with_brackets)
74-
tag_str = f"<{pos}>" + "".join(f"<{t}>" for t in filtered)
75-
return f"{word}{tag_str}", extra
74+
tag_str = f'<{pos}>' + ''.join(f'<{t}>' for t in filtered)
75+
return f'{word}{tag_str}', extra
7676

7777
consolidated = {}
7878
for item in raw_results:
7979
for src in item:
8080
norm_src, extra_src = normalize(src)
8181
if norm_src not in consolidated:
82-
consolidated[norm_src] = {"targets": {}, "extra_tags": []}
82+
consolidated[norm_src] = {'targets': {}, 'extra_tags': []}
8383
for tag in extra_src:
84-
if tag not in consolidated[norm_src]["extra_tags"]:
85-
consolidated[norm_src]["extra_tags"].append(tag)
84+
if tag not in consolidated[norm_src]['extra_tags']:
85+
consolidated[norm_src]['extra_tags'].append(tag)
8686
for tgt in item[src]:
8787
norm_tgt, _ = normalize(tgt)
88-
if norm_tgt not in consolidated[norm_src]["targets"]:
89-
consolidated[norm_src]["targets"][norm_tgt] = True
88+
if norm_tgt not in consolidated[norm_src]['targets']:
89+
consolidated[norm_src]['targets'][norm_tgt] = True
9090

9191
results = []
9292
for src, data in consolidated.items():
93-
tgt_list = list(data["targets"].keys())
94-
if data["extra_tags"]:
95-
extra_combined = "".join(data["extra_tags"])
93+
tgt_list = list(data['targets'].keys())
94+
if data['extra_tags']:
95+
extra_combined = ''.join(data['extra_tags'])
9696
entry = {
9797
src: tgt_list,
98-
"extra-tags": [extra_combined]
98+
'extra-tags': [extra_combined],
9999
}
100100
else:
101101
entry = {
102102
src: tgt_list,
103-
"extra-tags": []
103+
'extra-tags': [],
104104
}
105105
results.append(entry)
106106

apertium_apy/handlers/bilsearch.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from apertium_apy.utils.translation import translate_simple
66
from apertium_apy.utils import to_alpha3_code
77

8+
89
class BilsearchHandler(BaseHandler):
910
def get_pair_or_error(self, langpair):
1011
try:
@@ -23,15 +24,15 @@ def get_pair_or_error(self, langpair):
2324
@gen.coroutine
2425
def search_and_respond(self, pair, query):
2526
try:
26-
path, mode = self.bilsearch["-".join(pair)]
27+
path, mode = self.bilsearch['-'.join(pair)]
2728
commands = [['apertium', '-d', path, '-f', 'none', mode]]
2829
result = yield translate_simple(query, commands)
29-
resultPerSearch = result.split('\n\n')
30+
resultPerSearch = result.split('\n\n') # noqa: N806
3031
results = []
31-
for i, resultSet in enumerate(resultPerSearch):
32+
for i, resultSet in enumerate(resultPerSearch): # noqa: N806
3233
results.append({})
3334
for word in resultSet.strip().split('\n'):
34-
(l,r) = word.split(':')
35+
(l, r) = word.split(':')
3536
if l not in results[i]:
3637
results[i][l] = []
3738
results[i][l].append(r)

apertium_apy/handlers/embeddings.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
from apertium_apy.utils.translation import translate_simple
77
from apertium_apy.utils import to_alpha3_code
88

9+
910
class EmbeddingsHandler(BaseHandler):
1011
def get_pair_or_error(self, langpair):
1112
try:
1213
l1, l2 = map(to_alpha3_code, langpair.split('|'))
13-
in_mode = f"{l1}-{l2}"
14+
in_mode = f'{l1}-{l2}'
1415
except ValueError:
1516
self.send_error(400, explanation='That pair is invalid, use e.g. eng|spa')
1617
return None
@@ -24,7 +25,7 @@ def get_pair_or_error(self, langpair):
2425
@gen.coroutine
2526
def embed_and_respond(self, pair, query):
2627
try:
27-
raw_path, mode = self.embeddings["-".join(pair)]
28+
raw_path, mode = self.embeddings['-'.join(pair)]
2829
path = os.path.abspath(raw_path)
2930

3031
commands = [['apertium', '-d', path, '-f', 'none', mode]]

apertium_apy/handlers/translate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def maybe_strip_marks(self, mark_unknown, pair, translated):
4848
return re.sub(self.unknown_mark_re, r'\1', translated)
4949

5050
def note_unknown_tokens(self, pair, text):
51-
global missing_freqs_db
51+
global missing_freqs_db # noqa: F824
5252
if missing_freqs_db is not None:
5353
for token in re.findall(self.unknown_mark_re, text):
5454
missing_freqs_db.note_unknown(token, pair)

apertium_apy/mode_search.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,15 @@ def search_path(rootpath, include_pairs=True, verbosity=1):
7272
if mtype == 'bilsearch' or mtype == 'billookup' or mtype == 'embeddings':
7373
lang_src = to_alpha3_code(m.group(1))
7474
lang_trg = to_alpha3_code(m.group(2))
75-
lang_pair = f"{lang_src}-{lang_trg}"
76-
modename = f"{lang_pair}-{mtype}"
75+
lang_pair = f'{lang_src}-{lang_trg}'
76+
modename = f'{lang_pair}-{mtype}'
7777
dir_of_modes = os.path.dirname(dirpath)
7878
mode = (dir_of_modes, modename, lang_pair)
7979
modes[mtype].append(mode)
8080
elif mtype != 'pair':
81-
modename = m.group(1) # e.g. en-es-anmorph
81+
modename = m.group(1) # e.g. en-es-anmorph
8282
langlist = [to_alpha3_code(x) for x in m.group(2).split('-')]
83-
lang_pair = '-'.join(langlist) # e.g. en-es
83+
lang_pair = '-'.join(langlist) # e.g. en-es
8484
dir_of_modes = os.path.dirname(dirpath)
8585
mode = (dir_of_modes, modename, lang_pair)
8686
modes[mtype].append(mode)
@@ -121,7 +121,7 @@ def search_prefs(rootpath):
121121

122122

123123
def _log_modes(modes):
124-
"""Print given modes to log."""
124+
'''Print given modes to log.'''
125125
for mtype in modes:
126126
if modes[mtype]:
127-
logging.info('"%s" modes found:\n%s', mtype, '\n'.join(['\t'.join(m) for m in modes[mtype]]))
127+
logging.info("'%s' modes found:\n%s", mtype, '\n'.join(['\t'.join(m) for m in modes[mtype]]))

0 commit comments

Comments
 (0)