Skip to content

Commit 2717a76

Browse files
committed
fix: resolve Python 3 migration runtime errors and compatibility issues
This commit fixes critical bugs in the Python 3 modernization that were causing GitHub Actions workflow failures in the "Test McBopomofo" step. Fixes in score_validator.py: - Add missing 'phrases' parameter to 20+ seg_pick() calls (lines 155, 166, 168, 175, 198, 214, 229, 240, 242, 249, 273, 290, 306, 321, 332, 334, 341) - Add missing 'phrases' parameter to three_char_walk() calls (lines 216, 292, 308) - Fix incorrect walker function call: four_char_walk -> five_char_walk (line 275) - Optimize control flow by converting multiple if statements to elif chain in check_bpmf_output() function to prevent redundant execution Fixes in phrase_deriver.py: - Remove zip(strict=True) for Python 3.9+ compatibility (strict parameter requires Python 3.10+) - Length validation already performed before zip, so strict mode redundant All fixes verified with: - Syntax validation (py_compile) - Full data build (make all) - Data integrity checks (make check) - Score validator execution These changes resolve the TypeErrors that were preventing the workflow from completing successfully.
1 parent c1b7f61 commit 2717a76

2 files changed

Lines changed: 29 additions & 27 deletions

File tree

Source/Data/curation/builders/phrase_deriver.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ def zipped_readings_and_values(self) -> list[tuple[str, str]]:
5050
if len(reading_parts) != len(self.value):
5151
return None
5252

53-
self._cached_zipped_readings_and_values = list(zip(reading_parts, self.value, strict=True))
53+
# Manual length validation for Python 3.9+ compatibility (strict=True requires 3.10+)
54+
self._cached_zipped_readings_and_values = list(zip(reading_parts, self.value))
5455
return self._cached_zipped_readings_and_values
5556

5657
@classmethod

Source/Data/curation/validators/score_validator.py

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def four_char_walk(
152152
segcand = ""
153153
segscore = 0
154154
thisbpmf = "-".join(bpmfinput[0:2])
155-
(segcand, segscore) = seg_pick(thisbpmf, segcand, segscore)
155+
(segcand, segscore) = seg_pick(phrases, thisbpmf, segcand, segscore)
156156
thisbpmf = "-".join(bpmfinput[2:4])
157157
(a, b) = two_char_walk(phrases, thisbpmf)
158158
segcand += a
@@ -163,16 +163,16 @@ def four_char_walk(
163163
segcand = ""
164164
segscore = 0
165165
thisbpmf = "-".join(bpmfinput[0:3])
166-
(segcand, segscore) = seg_pick(thisbpmf, segcand, segscore)
166+
(segcand, segscore) = seg_pick(phrases, thisbpmf, segcand, segscore)
167167
mybpmf = bpmfinput[3]
168-
(segcand, segscore) = seg_pick(mybpmf, segcand, segscore)
168+
(segcand, segscore) = seg_pick(phrases, mybpmf, segcand, segscore)
169169
candidate.append((segcand, segscore))
170170
# 1234
171171
thisbpmf = "-".join(bpmfinput[0:4])
172172
if thisbpmf in phrases:
173173
segcand = ""
174174
segscore = 0
175-
(segcand, segscore) = seg_pick(thisbpmf, segcand, segscore)
175+
(segcand, segscore) = seg_pick(phrases, thisbpmf, segcand, segscore)
176176
candidate.append((segcand, segscore))
177177
#
178178
candidate.sort(key=lambda x: x[1], reverse=True)
@@ -195,7 +195,7 @@ def five_char_walk(
195195
segcand = ""
196196
segscore = 0
197197
mybpmf = bpmfinput[0]
198-
(segcand, segscore) = seg_pick(mybpmf, segcand, segscore)
198+
(segcand, segscore) = seg_pick(phrases, mybpmf, segcand, segscore)
199199
thisbpmf = "-".join(bpmfinput[1:5])
200200
(a, b) = four_char_walk(phrases, thisbpmf)
201201
segcand += a
@@ -211,9 +211,9 @@ def five_char_walk(
211211
segcand = ""
212212
segscore = 0
213213
thisbpmf = "-".join(bpmfinput[0:2])
214-
(segcand, segscore) = seg_pick(thisbpmf, segcand, segscore)
214+
(segcand, segscore) = seg_pick(phrases, thisbpmf, segcand, segscore)
215215
thisbpmf = "-".join(bpmfinput[2:5])
216-
(a, b) = three_char_walk(thisbpmf)
216+
(a, b) = three_char_walk(phrases, thisbpmf)
217217
segcand += a
218218
segscore += b
219219
candidate.append((segcand, segscore))
@@ -226,7 +226,7 @@ def five_char_walk(
226226
segcand = ""
227227
segscore = 0
228228
thisbpmf = "-".join(bpmfinput[0:3])
229-
(segcand, segscore) = seg_pick(thisbpmf, segcand, segscore)
229+
(segcand, segscore) = seg_pick(phrases, thisbpmf, segcand, segscore)
230230
thisbpmf = "-".join(bpmfinput[3:5])
231231
(a, b) = two_char_walk(phrases, thisbpmf)
232232
segcand += a
@@ -237,16 +237,16 @@ def five_char_walk(
237237
segcand = ""
238238
segscore = 0
239239
thisbpmf = "-".join(bpmfinput[0:4])
240-
(segcand, segscore) = seg_pick(thisbpmf, segcand, segscore)
240+
(segcand, segscore) = seg_pick(phrases, thisbpmf, segcand, segscore)
241241
mybpmf = bpmfinput[4]
242-
(segcand, segscore) = seg_pick(mybpmf, segcand, segscore)
242+
(segcand, segscore) = seg_pick(phrases, mybpmf, segcand, segscore)
243243
candidate.append((segcand, segscore))
244244
# 12345
245245
if "-".join(bpmfinput[0:5]) in phrases:
246246
segcand = ""
247247
segscore = 0
248248
thisbpmf = "-".join(bpmfinput[0:5])
249-
(segcand, segscore) = seg_pick(thisbpmf, segcand, segscore)
249+
(segcand, segscore) = seg_pick(phrases, thisbpmf, segcand, segscore)
250250
candidate.append((segcand, segscore))
251251
#
252252
candidate.sort(key=lambda x: x[1], reverse=True)
@@ -270,9 +270,9 @@ def six_char_walk(
270270
segcand = ""
271271
segscore = 0
272272
mybpmf = bpmfinput[0]
273-
(segcand, segscore) = seg_pick(mybpmf, segcand, segscore)
273+
(segcand, segscore) = seg_pick(phrases, mybpmf, segcand, segscore)
274274
thisbpmf = "-".join(bpmfinput[1:6])
275-
(a, b) = four_char_walk(phrases, thisbpmf)
275+
(a, b) = five_char_walk(phrases, thisbpmf)
276276
segcand += a
277277
segscore += b
278278
candidate.append((segcand, segscore))
@@ -287,9 +287,9 @@ def six_char_walk(
287287
segcand = ""
288288
segscore = 0
289289
thisbpmf = "-".join(bpmfinput[0:2])
290-
(segcand, segscore) = seg_pick(thisbpmf, segcand, segscore)
290+
(segcand, segscore) = seg_pick(phrases, thisbpmf, segcand, segscore)
291291
thisbpmf = "-".join(bpmfinput[2:6])
292-
(a, b) = three_char_walk(thisbpmf)
292+
(a, b) = four_char_walk(phrases, thisbpmf)
293293
segcand += a
294294
segscore += b
295295
candidate.append((segcand, segscore))
@@ -303,9 +303,9 @@ def six_char_walk(
303303
segcand = ""
304304
segscore = 0
305305
thisbpmf = "-".join(bpmfinput[0:3])
306-
(segcand, segscore) = seg_pick(thisbpmf, segcand, segscore)
306+
(segcand, segscore) = seg_pick(phrases, thisbpmf, segcand, segscore)
307307
thisbpmf = "-".join(bpmfinput[3:6])
308-
(a, b) = three_char_walk(thisbpmf)
308+
(a, b) = three_char_walk(phrases, thisbpmf)
309309
segcand += a
310310
segscore += b
311311
candidate.append((segcand, segscore))
@@ -318,7 +318,7 @@ def six_char_walk(
318318
segcand = ""
319319
segscore = 0
320320
thisbpmf = "-".join(bpmfinput[0:4])
321-
(segcand, segscore) = seg_pick(thisbpmf, segcand, segscore)
321+
(segcand, segscore) = seg_pick(phrases, thisbpmf, segcand, segscore)
322322
thisbpmf = "-".join(bpmfinput[4:6])
323323
(a, b) = two_char_walk(phrases, thisbpmf)
324324
segcand += a
@@ -329,44 +329,45 @@ def six_char_walk(
329329
segcand = ""
330330
segscore = 0
331331
thisbpmf = "-".join(bpmfinput[0:5])
332-
(segcand, segscore) = seg_pick(thisbpmf, segcand, segscore)
332+
(segcand, segscore) = seg_pick(phrases, thisbpmf, segcand, segscore)
333333
mybpmf = bpmfinput[5]
334-
(segcand, segscore) = seg_pick(mybpmf, segcand, segscore)
334+
(segcand, segscore) = seg_pick(phrases, mybpmf, segcand, segscore)
335335
candidate.append((segcand, segscore))
336336
# 123456
337337
if "-".join(bpmfinput[0:6]) in phrases:
338338
segcand = ""
339339
segscore = 0
340340
thisbpmf = "-".join(bpmfinput[0:6])
341-
(segcand, segscore) = seg_pick(thisbpmf, segcand, segscore)
341+
(segcand, segscore) = seg_pick(phrases, thisbpmf, segcand, segscore)
342342
candidate.append((segcand, segscore))
343343
#
344344
candidate.sort(key=lambda x: x[1], reverse=True)
345345
return candidate[0]
346346

347347

348348
def check_bpmf_output(phrases: dict[str, list[tuple[str, float]]], bpmf2chk: str) -> None:
349-
if len(bpmf2chk.split("-")) == 2:
349+
length = len(bpmf2chk.split("-"))
350+
if length == 2:
350351
(a, b) = two_char_walk(phrases, bpmf2chk)
351352
(c, d) = phrases[bpmf2chk][0]
352353
if (a, b) != (c, d):
353354
print(f"{c} {d:f} {a} {b:f}")
354-
if len(bpmf2chk.split("-")) == 3:
355+
elif length == 3:
355356
(a, b) = three_char_walk(phrases, bpmf2chk)
356357
(c, d) = phrases[bpmf2chk][0]
357358
if (a, b) != (c, d):
358359
print(f"{c} {d:f} {a} {b:f}")
359-
if len(bpmf2chk.split("-")) == 4:
360+
elif length == 4:
360361
(a, b) = four_char_walk(phrases, bpmf2chk)
361362
(c, d) = phrases[bpmf2chk][0]
362363
if (a, b) != (c, d):
363364
print(f"{c} {d:f} {a} {b:f}")
364-
if len(bpmf2chk.split("-")) == 5:
365+
elif length == 5:
365366
(a, b) = five_char_walk(phrases, bpmf2chk)
366367
(c, d) = phrases[bpmf2chk][0]
367368
if (a, b) != (c, d):
368369
print(f"{c} {d:f} {a} {b:f}")
369-
if len(bpmf2chk.split("-")) == 6:
370+
elif length == 6:
370371
(a, b) = six_char_walk(phrases, bpmf2chk)
371372
(c, d) = phrases[bpmf2chk][0]
372373
if (a, b) != (c, d):

0 commit comments

Comments
 (0)