fonttools 4.59.1__cp310-cp310-win_amd64.whl → 4.60.0__cp310-cp310-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of fonttools might be problematic. Click here for more details.

Files changed (51) hide show
  1. fontTools/__init__.py +1 -1
  2. fontTools/annotations.py +30 -0
  3. fontTools/cu2qu/cu2qu.c +1185 -971
  4. fontTools/cu2qu/cu2qu.cp310-win_amd64.pyd +0 -0
  5. fontTools/cu2qu/cu2qu.py +36 -4
  6. fontTools/feaLib/builder.py +9 -3
  7. fontTools/feaLib/lexer.c +18 -12
  8. fontTools/feaLib/lexer.cp310-win_amd64.pyd +0 -0
  9. fontTools/feaLib/parser.py +11 -1
  10. fontTools/feaLib/variableScalar.py +6 -1
  11. fontTools/misc/bezierTools.c +18 -12
  12. fontTools/misc/bezierTools.cp310-win_amd64.pyd +0 -0
  13. fontTools/misc/enumTools.py +23 -0
  14. fontTools/misc/textTools.py +4 -2
  15. fontTools/pens/filterPen.py +218 -26
  16. fontTools/pens/momentsPen.c +18 -12
  17. fontTools/pens/momentsPen.cp310-win_amd64.pyd +0 -0
  18. fontTools/pens/pointPen.py +40 -6
  19. fontTools/qu2cu/qu2cu.c +30 -16
  20. fontTools/qu2cu/qu2cu.cp310-win_amd64.pyd +0 -0
  21. fontTools/subset/__init__.py +1 -0
  22. fontTools/ttLib/tables/_a_v_a_r.py +4 -2
  23. fontTools/ttLib/tables/_n_a_m_e.py +11 -6
  24. fontTools/ttLib/tables/_p_o_s_t.py +5 -5
  25. fontTools/ufoLib/__init__.py +279 -176
  26. fontTools/ufoLib/converters.py +14 -5
  27. fontTools/ufoLib/filenames.py +16 -6
  28. fontTools/ufoLib/glifLib.py +286 -190
  29. fontTools/ufoLib/kerning.py +32 -12
  30. fontTools/ufoLib/utils.py +41 -13
  31. fontTools/ufoLib/validators.py +121 -97
  32. fontTools/varLib/__init__.py +80 -1
  33. fontTools/varLib/avar/__init__.py +0 -0
  34. fontTools/varLib/avar/__main__.py +72 -0
  35. fontTools/varLib/avar/build.py +79 -0
  36. fontTools/varLib/avar/map.py +108 -0
  37. fontTools/varLib/avar/plan.py +1004 -0
  38. fontTools/varLib/{avar.py → avar/unbuild.py} +70 -59
  39. fontTools/varLib/avarPlanner.py +3 -999
  40. fontTools/varLib/instancer/__init__.py +56 -18
  41. fontTools/varLib/interpolatableHelpers.py +3 -0
  42. fontTools/varLib/iup.c +24 -14
  43. fontTools/varLib/iup.cp310-win_amd64.pyd +0 -0
  44. {fonttools-4.59.1.dist-info → fonttools-4.60.0.dist-info}/METADATA +43 -2
  45. {fonttools-4.59.1.dist-info → fonttools-4.60.0.dist-info}/RECORD +51 -44
  46. {fonttools-4.59.1.data → fonttools-4.60.0.data}/data/share/man/man1/ttx.1 +0 -0
  47. {fonttools-4.59.1.dist-info → fonttools-4.60.0.dist-info}/WHEEL +0 -0
  48. {fonttools-4.59.1.dist-info → fonttools-4.60.0.dist-info}/entry_points.txt +0 -0
  49. {fonttools-4.59.1.dist-info → fonttools-4.60.0.dist-info}/licenses/LICENSE +0 -0
  50. {fonttools-4.59.1.dist-info → fonttools-4.60.0.dist-info}/licenses/LICENSE.external +0 -0
  51. {fonttools-4.59.1.dist-info → fonttools-4.60.0.dist-info}/top_level.txt +0 -0
@@ -1,18 +1,25 @@
1
1
  """Various low level data validators."""
2
2
 
3
+ from __future__ import annotations
4
+
3
5
  import calendar
4
- from collections.abc import Mapping
6
+ from collections.abc import Mapping, Sequence
5
7
  from io import open
6
8
 
7
9
  import fontTools.misc.filesystem as fs
10
+ from typing import Any, Type, Optional, Union
11
+
12
+ from fontTools.annotations import IntFloat
8
13
  from fontTools.ufoLib.utils import numberTypes
9
14
 
15
+ GenericDict = dict[str, tuple[Union[type, tuple[Type[Any], ...]], bool]]
16
+
10
17
  # -------
11
18
  # Generic
12
19
  # -------
13
20
 
14
21
 
15
- def isDictEnough(value):
22
+ def isDictEnough(value: Any) -> bool:
16
23
  """
17
24
  Some objects will likely come in that aren't
18
25
  dicts but are dict-ish enough.
@@ -25,14 +32,14 @@ def isDictEnough(value):
25
32
  return True
26
33
 
27
34
 
28
- def genericTypeValidator(value, typ):
35
+ def genericTypeValidator(value: Any, typ: Type[Any]) -> bool:
29
36
  """
30
37
  Generic. (Added at version 2.)
31
38
  """
32
39
  return isinstance(value, typ)
33
40
 
34
41
 
35
- def genericIntListValidator(values, validValues):
42
+ def genericIntListValidator(values: Any, validValues: Sequence[int]) -> bool:
36
43
  """
37
44
  Generic. (Added at version 2.)
38
45
  """
@@ -48,7 +55,7 @@ def genericIntListValidator(values, validValues):
48
55
  return True
49
56
 
50
57
 
51
- def genericNonNegativeIntValidator(value):
58
+ def genericNonNegativeIntValidator(value: Any) -> bool:
52
59
  """
53
60
  Generic. (Added at version 3.)
54
61
  """
@@ -59,7 +66,7 @@ def genericNonNegativeIntValidator(value):
59
66
  return True
60
67
 
61
68
 
62
- def genericNonNegativeNumberValidator(value):
69
+ def genericNonNegativeNumberValidator(value: Any) -> bool:
63
70
  """
64
71
  Generic. (Added at version 3.)
65
72
  """
@@ -70,7 +77,7 @@ def genericNonNegativeNumberValidator(value):
70
77
  return True
71
78
 
72
79
 
73
- def genericDictValidator(value, prototype):
80
+ def genericDictValidator(value: Any, prototype: GenericDict) -> bool:
74
81
  """
75
82
  Generic. (Added at version 3.)
76
83
  """
@@ -104,7 +111,7 @@ def genericDictValidator(value, prototype):
104
111
  # Data Validators
105
112
 
106
113
 
107
- def fontInfoStyleMapStyleNameValidator(value):
114
+ def fontInfoStyleMapStyleNameValidator(value: Any) -> bool:
108
115
  """
109
116
  Version 2+.
110
117
  """
@@ -112,7 +119,7 @@ def fontInfoStyleMapStyleNameValidator(value):
112
119
  return value in options
113
120
 
114
121
 
115
- def fontInfoOpenTypeGaspRangeRecordsValidator(value):
122
+ def fontInfoOpenTypeGaspRangeRecordsValidator(value: Any) -> bool:
116
123
  """
117
124
  Version 3+.
118
125
  """
@@ -121,7 +128,9 @@ def fontInfoOpenTypeGaspRangeRecordsValidator(value):
121
128
  if len(value) == 0:
122
129
  return True
123
130
  validBehaviors = [0, 1, 2, 3]
124
- dictPrototype = dict(rangeMaxPPEM=(int, True), rangeGaspBehavior=(list, True))
131
+ dictPrototype: GenericDict = dict(
132
+ rangeMaxPPEM=(int, True), rangeGaspBehavior=(list, True)
133
+ )
125
134
  ppemOrder = []
126
135
  for rangeRecord in value:
127
136
  if not genericDictValidator(rangeRecord, dictPrototype):
@@ -140,7 +149,7 @@ def fontInfoOpenTypeGaspRangeRecordsValidator(value):
140
149
  return True
141
150
 
142
151
 
143
- def fontInfoOpenTypeHeadCreatedValidator(value):
152
+ def fontInfoOpenTypeHeadCreatedValidator(value: Any) -> bool:
144
153
  """
145
154
  Version 2+.
146
155
  """
@@ -152,61 +161,61 @@ def fontInfoOpenTypeHeadCreatedValidator(value):
152
161
  return False
153
162
  if value.count(" ") != 1:
154
163
  return False
155
- date, time = value.split(" ")
156
- if date.count("/") != 2:
164
+ strDate, strTime = value.split(" ")
165
+ if strDate.count("/") != 2:
157
166
  return False
158
- if time.count(":") != 2:
167
+ if strTime.count(":") != 2:
159
168
  return False
160
169
  # date
161
- year, month, day = date.split("/")
162
- if len(year) != 4:
170
+ strYear, strMonth, strDay = strDate.split("/")
171
+ if len(strYear) != 4:
163
172
  return False
164
- if len(month) != 2:
173
+ if len(strMonth) != 2:
165
174
  return False
166
- if len(day) != 2:
175
+ if len(strDay) != 2:
167
176
  return False
168
177
  try:
169
- year = int(year)
170
- month = int(month)
171
- day = int(day)
178
+ intYear = int(strYear)
179
+ intMonth = int(strMonth)
180
+ intDay = int(strDay)
172
181
  except ValueError:
173
182
  return False
174
- if month < 1 or month > 12:
183
+ if intMonth < 1 or intMonth > 12:
175
184
  return False
176
- monthMaxDay = calendar.monthrange(year, month)[1]
177
- if day < 1 or day > monthMaxDay:
185
+ monthMaxDay = calendar.monthrange(intYear, intMonth)[1]
186
+ if intDay < 1 or intDay > monthMaxDay:
178
187
  return False
179
188
  # time
180
- hour, minute, second = time.split(":")
181
- if len(hour) != 2:
189
+ strHour, strMinute, strSecond = strTime.split(":")
190
+ if len(strHour) != 2:
182
191
  return False
183
- if len(minute) != 2:
192
+ if len(strMinute) != 2:
184
193
  return False
185
- if len(second) != 2:
194
+ if len(strSecond) != 2:
186
195
  return False
187
196
  try:
188
- hour = int(hour)
189
- minute = int(minute)
190
- second = int(second)
197
+ intHour = int(strHour)
198
+ intMinute = int(strMinute)
199
+ intSecond = int(strSecond)
191
200
  except ValueError:
192
201
  return False
193
- if hour < 0 or hour > 23:
202
+ if intHour < 0 or intHour > 23:
194
203
  return False
195
- if minute < 0 or minute > 59:
204
+ if intMinute < 0 or intMinute > 59:
196
205
  return False
197
- if second < 0 or second > 59:
206
+ if intSecond < 0 or intSecond > 59:
198
207
  return False
199
208
  # fallback
200
209
  return True
201
210
 
202
211
 
203
- def fontInfoOpenTypeNameRecordsValidator(value):
212
+ def fontInfoOpenTypeNameRecordsValidator(value: Any) -> bool:
204
213
  """
205
214
  Version 3+.
206
215
  """
207
216
  if not isinstance(value, list):
208
217
  return False
209
- dictPrototype = dict(
218
+ dictPrototype: GenericDict = dict(
210
219
  nameID=(int, True),
211
220
  platformID=(int, True),
212
221
  encodingID=(int, True),
@@ -219,7 +228,7 @@ def fontInfoOpenTypeNameRecordsValidator(value):
219
228
  return True
220
229
 
221
230
 
222
- def fontInfoOpenTypeOS2WeightClassValidator(value):
231
+ def fontInfoOpenTypeOS2WeightClassValidator(value: Any) -> bool:
223
232
  """
224
233
  Version 2+.
225
234
  """
@@ -230,7 +239,7 @@ def fontInfoOpenTypeOS2WeightClassValidator(value):
230
239
  return True
231
240
 
232
241
 
233
- def fontInfoOpenTypeOS2WidthClassValidator(value):
242
+ def fontInfoOpenTypeOS2WidthClassValidator(value: Any) -> bool:
234
243
  """
235
244
  Version 2+.
236
245
  """
@@ -243,7 +252,7 @@ def fontInfoOpenTypeOS2WidthClassValidator(value):
243
252
  return True
244
253
 
245
254
 
246
- def fontInfoVersion2OpenTypeOS2PanoseValidator(values):
255
+ def fontInfoVersion2OpenTypeOS2PanoseValidator(values: Any) -> bool:
247
256
  """
248
257
  Version 2.
249
258
  """
@@ -258,7 +267,7 @@ def fontInfoVersion2OpenTypeOS2PanoseValidator(values):
258
267
  return True
259
268
 
260
269
 
261
- def fontInfoVersion3OpenTypeOS2PanoseValidator(values):
270
+ def fontInfoVersion3OpenTypeOS2PanoseValidator(values: Any) -> bool:
262
271
  """
263
272
  Version 3+.
264
273
  """
@@ -275,7 +284,7 @@ def fontInfoVersion3OpenTypeOS2PanoseValidator(values):
275
284
  return True
276
285
 
277
286
 
278
- def fontInfoOpenTypeOS2FamilyClassValidator(values):
287
+ def fontInfoOpenTypeOS2FamilyClassValidator(values: Any) -> bool:
279
288
  """
280
289
  Version 2+.
281
290
  """
@@ -294,7 +303,7 @@ def fontInfoOpenTypeOS2FamilyClassValidator(values):
294
303
  return True
295
304
 
296
305
 
297
- def fontInfoPostscriptBluesValidator(values):
306
+ def fontInfoPostscriptBluesValidator(values: Any) -> bool:
298
307
  """
299
308
  Version 2+.
300
309
  """
@@ -310,7 +319,7 @@ def fontInfoPostscriptBluesValidator(values):
310
319
  return True
311
320
 
312
321
 
313
- def fontInfoPostscriptOtherBluesValidator(values):
322
+ def fontInfoPostscriptOtherBluesValidator(values: Any) -> bool:
314
323
  """
315
324
  Version 2+.
316
325
  """
@@ -326,7 +335,7 @@ def fontInfoPostscriptOtherBluesValidator(values):
326
335
  return True
327
336
 
328
337
 
329
- def fontInfoPostscriptStemsValidator(values):
338
+ def fontInfoPostscriptStemsValidator(values: Any) -> bool:
330
339
  """
331
340
  Version 2+.
332
341
  """
@@ -340,7 +349,7 @@ def fontInfoPostscriptStemsValidator(values):
340
349
  return True
341
350
 
342
351
 
343
- def fontInfoPostscriptWindowsCharacterSetValidator(value):
352
+ def fontInfoPostscriptWindowsCharacterSetValidator(value: Any) -> bool:
344
353
  """
345
354
  Version 2+.
346
355
  """
@@ -350,21 +359,21 @@ def fontInfoPostscriptWindowsCharacterSetValidator(value):
350
359
  return True
351
360
 
352
361
 
353
- def fontInfoWOFFMetadataUniqueIDValidator(value):
362
+ def fontInfoWOFFMetadataUniqueIDValidator(value: Any) -> bool:
354
363
  """
355
364
  Version 3+.
356
365
  """
357
- dictPrototype = dict(id=(str, True))
366
+ dictPrototype: GenericDict = dict(id=(str, True))
358
367
  if not genericDictValidator(value, dictPrototype):
359
368
  return False
360
369
  return True
361
370
 
362
371
 
363
- def fontInfoWOFFMetadataVendorValidator(value):
372
+ def fontInfoWOFFMetadataVendorValidator(value: Any) -> bool:
364
373
  """
365
374
  Version 3+.
366
375
  """
367
- dictPrototype = {
376
+ dictPrototype: GenericDict = {
368
377
  "name": (str, True),
369
378
  "url": (str, False),
370
379
  "dir": (str, False),
@@ -377,11 +386,11 @@ def fontInfoWOFFMetadataVendorValidator(value):
377
386
  return True
378
387
 
379
388
 
380
- def fontInfoWOFFMetadataCreditsValidator(value):
389
+ def fontInfoWOFFMetadataCreditsValidator(value: Any) -> bool:
381
390
  """
382
391
  Version 3+.
383
392
  """
384
- dictPrototype = dict(credits=(list, True))
393
+ dictPrototype: GenericDict = dict(credits=(list, True))
385
394
  if not genericDictValidator(value, dictPrototype):
386
395
  return False
387
396
  if not len(value["credits"]):
@@ -401,11 +410,11 @@ def fontInfoWOFFMetadataCreditsValidator(value):
401
410
  return True
402
411
 
403
412
 
404
- def fontInfoWOFFMetadataDescriptionValidator(value):
413
+ def fontInfoWOFFMetadataDescriptionValidator(value: Any) -> bool:
405
414
  """
406
415
  Version 3+.
407
416
  """
408
- dictPrototype = dict(url=(str, False), text=(list, True))
417
+ dictPrototype: GenericDict = dict(url=(str, False), text=(list, True))
409
418
  if not genericDictValidator(value, dictPrototype):
410
419
  return False
411
420
  for text in value["text"]:
@@ -414,11 +423,13 @@ def fontInfoWOFFMetadataDescriptionValidator(value):
414
423
  return True
415
424
 
416
425
 
417
- def fontInfoWOFFMetadataLicenseValidator(value):
426
+ def fontInfoWOFFMetadataLicenseValidator(value: Any) -> bool:
418
427
  """
419
428
  Version 3+.
420
429
  """
421
- dictPrototype = dict(url=(str, False), text=(list, False), id=(str, False))
430
+ dictPrototype: GenericDict = dict(
431
+ url=(str, False), text=(list, False), id=(str, False)
432
+ )
422
433
  if not genericDictValidator(value, dictPrototype):
423
434
  return False
424
435
  if "text" in value:
@@ -428,11 +439,11 @@ def fontInfoWOFFMetadataLicenseValidator(value):
428
439
  return True
429
440
 
430
441
 
431
- def fontInfoWOFFMetadataTrademarkValidator(value):
442
+ def fontInfoWOFFMetadataTrademarkValidator(value: Any) -> bool:
432
443
  """
433
444
  Version 3+.
434
445
  """
435
- dictPrototype = dict(text=(list, True))
446
+ dictPrototype: GenericDict = dict(text=(list, True))
436
447
  if not genericDictValidator(value, dictPrototype):
437
448
  return False
438
449
  for text in value["text"]:
@@ -441,11 +452,11 @@ def fontInfoWOFFMetadataTrademarkValidator(value):
441
452
  return True
442
453
 
443
454
 
444
- def fontInfoWOFFMetadataCopyrightValidator(value):
455
+ def fontInfoWOFFMetadataCopyrightValidator(value: Any) -> bool:
445
456
  """
446
457
  Version 3+.
447
458
  """
448
- dictPrototype = dict(text=(list, True))
459
+ dictPrototype: GenericDict = dict(text=(list, True))
449
460
  if not genericDictValidator(value, dictPrototype):
450
461
  return False
451
462
  for text in value["text"]:
@@ -454,11 +465,15 @@ def fontInfoWOFFMetadataCopyrightValidator(value):
454
465
  return True
455
466
 
456
467
 
457
- def fontInfoWOFFMetadataLicenseeValidator(value):
468
+ def fontInfoWOFFMetadataLicenseeValidator(value: Any) -> bool:
458
469
  """
459
470
  Version 3+.
460
471
  """
461
- dictPrototype = {"name": (str, True), "dir": (str, False), "class": (str, False)}
472
+ dictPrototype: GenericDict = {
473
+ "name": (str, True),
474
+ "dir": (str, False),
475
+ "class": (str, False),
476
+ }
462
477
  if not genericDictValidator(value, dictPrototype):
463
478
  return False
464
479
  if "dir" in value and value.get("dir") not in ("ltr", "rtl"):
@@ -466,11 +481,11 @@ def fontInfoWOFFMetadataLicenseeValidator(value):
466
481
  return True
467
482
 
468
483
 
469
- def fontInfoWOFFMetadataTextValue(value):
484
+ def fontInfoWOFFMetadataTextValue(value: Any) -> bool:
470
485
  """
471
486
  Version 3+.
472
487
  """
473
- dictPrototype = {
488
+ dictPrototype: GenericDict = {
474
489
  "text": (str, True),
475
490
  "language": (str, False),
476
491
  "dir": (str, False),
@@ -483,7 +498,7 @@ def fontInfoWOFFMetadataTextValue(value):
483
498
  return True
484
499
 
485
500
 
486
- def fontInfoWOFFMetadataExtensionsValidator(value):
501
+ def fontInfoWOFFMetadataExtensionsValidator(value: Any) -> bool:
487
502
  """
488
503
  Version 3+.
489
504
  """
@@ -497,11 +512,13 @@ def fontInfoWOFFMetadataExtensionsValidator(value):
497
512
  return True
498
513
 
499
514
 
500
- def fontInfoWOFFMetadataExtensionValidator(value):
515
+ def fontInfoWOFFMetadataExtensionValidator(value: Any) -> bool:
501
516
  """
502
517
  Version 3+.
503
518
  """
504
- dictPrototype = dict(names=(list, False), items=(list, True), id=(str, False))
519
+ dictPrototype: GenericDict = dict(
520
+ names=(list, False), items=(list, True), id=(str, False)
521
+ )
505
522
  if not genericDictValidator(value, dictPrototype):
506
523
  return False
507
524
  if "names" in value:
@@ -514,11 +531,13 @@ def fontInfoWOFFMetadataExtensionValidator(value):
514
531
  return True
515
532
 
516
533
 
517
- def fontInfoWOFFMetadataExtensionItemValidator(value):
534
+ def fontInfoWOFFMetadataExtensionItemValidator(value: Any) -> bool:
518
535
  """
519
536
  Version 3+.
520
537
  """
521
- dictPrototype = dict(id=(str, False), names=(list, True), values=(list, True))
538
+ dictPrototype: GenericDict = dict(
539
+ id=(str, False), names=(list, True), values=(list, True)
540
+ )
522
541
  if not genericDictValidator(value, dictPrototype):
523
542
  return False
524
543
  for name in value["names"]:
@@ -530,11 +549,11 @@ def fontInfoWOFFMetadataExtensionItemValidator(value):
530
549
  return True
531
550
 
532
551
 
533
- def fontInfoWOFFMetadataExtensionNameValidator(value):
552
+ def fontInfoWOFFMetadataExtensionNameValidator(value: Any) -> bool:
534
553
  """
535
554
  Version 3+.
536
555
  """
537
- dictPrototype = {
556
+ dictPrototype: GenericDict = {
538
557
  "text": (str, True),
539
558
  "language": (str, False),
540
559
  "dir": (str, False),
@@ -547,11 +566,11 @@ def fontInfoWOFFMetadataExtensionNameValidator(value):
547
566
  return True
548
567
 
549
568
 
550
- def fontInfoWOFFMetadataExtensionValueValidator(value):
569
+ def fontInfoWOFFMetadataExtensionValueValidator(value: Any) -> bool:
551
570
  """
552
571
  Version 3+.
553
572
  """
554
- dictPrototype = {
573
+ dictPrototype: GenericDict = {
555
574
  "text": (str, True),
556
575
  "language": (str, False),
557
576
  "dir": (str, False),
@@ -569,7 +588,7 @@ def fontInfoWOFFMetadataExtensionValueValidator(value):
569
588
  # ----------
570
589
 
571
590
 
572
- def guidelinesValidator(value, identifiers=None):
591
+ def guidelinesValidator(value: Any, identifiers: Optional[set[str]] = None) -> bool:
573
592
  """
574
593
  Version 3+.
575
594
  """
@@ -588,7 +607,7 @@ def guidelinesValidator(value, identifiers=None):
588
607
  return True
589
608
 
590
609
 
591
- _guidelineDictPrototype = dict(
610
+ _guidelineDictPrototype: GenericDict = dict(
592
611
  x=((int, float), False),
593
612
  y=((int, float), False),
594
613
  angle=((int, float), False),
@@ -598,7 +617,7 @@ _guidelineDictPrototype = dict(
598
617
  )
599
618
 
600
619
 
601
- def guidelineValidator(value):
620
+ def guidelineValidator(value: Any) -> bool:
602
621
  """
603
622
  Version 3+.
604
623
  """
@@ -639,7 +658,7 @@ def guidelineValidator(value):
639
658
  # -------
640
659
 
641
660
 
642
- def anchorsValidator(value, identifiers=None):
661
+ def anchorsValidator(value: Any, identifiers: Optional[set[str]] = None) -> bool:
643
662
  """
644
663
  Version 3+.
645
664
  """
@@ -658,7 +677,7 @@ def anchorsValidator(value, identifiers=None):
658
677
  return True
659
678
 
660
679
 
661
- _anchorDictPrototype = dict(
680
+ _anchorDictPrototype: GenericDict = dict(
662
681
  x=((int, float), False),
663
682
  y=((int, float), False),
664
683
  name=(str, False),
@@ -667,7 +686,7 @@ _anchorDictPrototype = dict(
667
686
  )
668
687
 
669
688
 
670
- def anchorValidator(value):
689
+ def anchorValidator(value: Any) -> bool:
671
690
  """
672
691
  Version 3+.
673
692
  """
@@ -694,7 +713,7 @@ def anchorValidator(value):
694
713
  # ----------
695
714
 
696
715
 
697
- def identifierValidator(value):
716
+ def identifierValidator(value: Any) -> bool:
698
717
  """
699
718
  Version 3+.
700
719
 
@@ -714,8 +733,8 @@ def identifierValidator(value):
714
733
  if len(value) > 100:
715
734
  return False
716
735
  for c in value:
717
- c = ord(c)
718
- if c < validCharactersMin or c > validCharactersMax:
736
+ i = ord(c)
737
+ if i < validCharactersMin or i > validCharactersMax:
719
738
  return False
720
739
  return True
721
740
 
@@ -725,7 +744,7 @@ def identifierValidator(value):
725
744
  # -----
726
745
 
727
746
 
728
- def colorValidator(value):
747
+ def colorValidator(value: Any) -> bool:
729
748
  """
730
749
  Version 3+.
731
750
 
@@ -776,22 +795,21 @@ def colorValidator(value):
776
795
  for part in parts:
777
796
  part = part.strip()
778
797
  converted = False
798
+ number: IntFloat
779
799
  try:
780
- part = int(part)
800
+ number = int(part)
781
801
  converted = True
782
802
  except ValueError:
783
803
  pass
784
804
  if not converted:
785
805
  try:
786
- part = float(part)
806
+ number = float(part)
787
807
  converted = True
788
808
  except ValueError:
789
809
  pass
790
810
  if not converted:
791
811
  return False
792
- if part < 0:
793
- return False
794
- if part > 1:
812
+ if not 0 <= number <= 1:
795
813
  return False
796
814
  return True
797
815
 
@@ -800,9 +818,9 @@ def colorValidator(value):
800
818
  # image
801
819
  # -----
802
820
 
803
- pngSignature = b"\x89PNG\r\n\x1a\n"
821
+ pngSignature: bytes = b"\x89PNG\r\n\x1a\n"
804
822
 
805
- _imageDictPrototype = dict(
823
+ _imageDictPrototype: GenericDict = dict(
806
824
  fileName=(str, True),
807
825
  xScale=((int, float), False),
808
826
  xyScale=((int, float), False),
@@ -830,7 +848,11 @@ def imageValidator(value):
830
848
  return True
831
849
 
832
850
 
833
- def pngValidator(path=None, data=None, fileObj=None):
851
+ def pngValidator(
852
+ path: Optional[str] = None,
853
+ data: Optional[bytes] = None,
854
+ fileObj: Optional[Any] = None,
855
+ ) -> tuple[bool, Any]:
834
856
  """
835
857
  Version 3+.
836
858
 
@@ -856,7 +878,9 @@ def pngValidator(path=None, data=None, fileObj=None):
856
878
  # -------------------
857
879
 
858
880
 
859
- def layerContentsValidator(value, ufoPathOrFileSystem):
881
+ def layerContentsValidator(
882
+ value: Any, ufoPathOrFileSystem: Union[str, fs.base.FS]
883
+ ) -> tuple[bool, Optional[str]]:
860
884
  """
861
885
  Check the validity of layercontents.plist.
862
886
  Version 3+.
@@ -930,7 +954,7 @@ def layerContentsValidator(value, ufoPathOrFileSystem):
930
954
  # ------------
931
955
 
932
956
 
933
- def groupsValidator(value):
957
+ def groupsValidator(value: Any) -> tuple[bool, Optional[str]]:
934
958
  """
935
959
  Check the validity of the groups.
936
960
  Version 3+ (though it's backwards compatible with UFO 1 and UFO 2).
@@ -977,8 +1001,8 @@ def groupsValidator(value):
977
1001
  bogusFormatMessage = "The group data is not in the correct format."
978
1002
  if not isDictEnough(value):
979
1003
  return False, bogusFormatMessage
980
- firstSideMapping = {}
981
- secondSideMapping = {}
1004
+ firstSideMapping: dict[str, str] = {}
1005
+ secondSideMapping: dict[str, str] = {}
982
1006
  for groupName, glyphList in value.items():
983
1007
  if not isinstance(groupName, (str)):
984
1008
  return False, bogusFormatMessage
@@ -1022,7 +1046,7 @@ def groupsValidator(value):
1022
1046
  # -------------
1023
1047
 
1024
1048
 
1025
- def kerningValidator(data):
1049
+ def kerningValidator(data: Any) -> tuple[bool, Optional[str]]:
1026
1050
  """
1027
1051
  Check the validity of the kerning data structure.
1028
1052
  Version 3+ (though it's backwards compatible with UFO 1 and UFO 2).
@@ -1068,7 +1092,7 @@ def kerningValidator(data):
1068
1092
  _bogusLibFormatMessage = "The lib data is not in the correct format: %s"
1069
1093
 
1070
1094
 
1071
- def fontLibValidator(value):
1095
+ def fontLibValidator(value: Any) -> tuple[bool, Optional[str]]:
1072
1096
  """
1073
1097
  Check the validity of the lib.
1074
1098
  Version 3+ (though it's backwards compatible with UFO 1 and UFO 2).
@@ -1140,7 +1164,7 @@ def fontLibValidator(value):
1140
1164
  # --------
1141
1165
 
1142
1166
 
1143
- def glyphLibValidator(value):
1167
+ def glyphLibValidator(value: Any) -> tuple[bool, Optional[str]]:
1144
1168
  """
1145
1169
  Check the validity of the lib.
1146
1170
  Version 3+ (though it's backwards compatible with UFO 1 and UFO 2).