Skip to content

Commit 00fa6b3

Browse files
authored
Improve typing of flags (#23)
1 parent e7c3e5a commit 00fa6b3

2 files changed

Lines changed: 33 additions & 29 deletions

File tree

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,22 @@ and this project uses YYYY.MM.DD [calendar versioning](https://calver.org/).
77

88
## Unreleased
99

10+
### Added
11+
12+
- Missing `no-mac-names` flag for `font.generateTtc`
13+
1014
### Changed
1115

1216
- Several class attributes to properties to:
1317
- Handle setters that accept a wider range of types than returned by their
1418
getters
1519
- Represent attributes that are read-only
20+
- Widen typing of flags to accept a string for a single flag or a sequence
21+
of strings
22+
23+
### Fixed
24+
25+
- `font.gasp` to be a tuple of arbitrary length
1626

1727
## 2025.11.28 - 2025-11-28
1828

src/fontforge-stubs/__init__.pyi

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -468,13 +468,15 @@ def fontsInFile(filename: str) -> tuple[str, ...]:
468468
"""
469469
...
470470

471+
_F = TypeVar("_F", bound=str)
472+
_Flags = _F | Sequence[_F]
473+
471474
def open(
472475
filename: str,
473-
flags: tuple[
476+
flags: _Flags[
474477
Literal[
475478
"fstypepermitted", "allglyphsinttc", "fontlint", "hidewindow", "alltables"
476479
],
477-
...,
478480
]
479481
| int
480482
| None = None,
@@ -1509,7 +1511,7 @@ class contour(Sequence[point]):
15091511
def simplify(
15101512
self,
15111513
error_bound: float = 1,
1512-
flags: tuple[
1514+
flags: _Flags[
15131515
Literal[
15141516
"ignoreslopes",
15151517
"ignoreextrema",
@@ -1521,7 +1523,6 @@ class contour(Sequence[point]):
15211523
"setstarttoextremum",
15221524
"removesingletonpoints",
15231525
],
1524-
...,
15251526
] = (),
15261527
tan_bounds: float = 0.2,
15271528
linefixup: float = 2,
@@ -1874,7 +1875,7 @@ class layer(Sequence[contour]):
18741875
def simplify(
18751876
self,
18761877
error_bound: float = 1,
1877-
flags: tuple[
1878+
flags: _Flags[
18781879
Literal[
18791880
"ignoreslopes",
18801881
"ignoreextrema",
@@ -1886,7 +1887,6 @@ class layer(Sequence[contour]):
18861887
"setstarttoextremum",
18871888
"removesingletonpoints",
18881889
],
1889-
...,
18901890
] = (),
18911891
tan_bounds: float = 0.2,
18921892
linefixup: float = 2,
@@ -3358,7 +3358,7 @@ class glyph:
33583358
def importOutlines(
33593359
self,
33603360
filename: str,
3361-
flags: tuple[Literal["handle_eraser", "correctdir"], ...],
3361+
flags: _Flags[Literal["handle_eraser", "correctdir"]],
33623362
/,
33633363
) -> Self:
33643364
"""
@@ -3472,7 +3472,7 @@ class glyph:
34723472
self,
34733473
layer: layer | contour,
34743474
layer_index: int | str,
3475-
flags: tuple[
3475+
flags: _Flags[
34763476
Literal[
34773477
"select_none",
34783478
"select_all",
@@ -3484,7 +3484,6 @@ class glyph:
34843484
"force",
34853485
"hvcurve",
34863486
],
3487-
...,
34883487
] = ("select_all", "by_geom"),
34893488
) -> Self:
34903489
"""
@@ -3562,7 +3561,7 @@ class glyph:
35623561
def simplify(
35633562
self,
35643563
error_bound: float | None = None,
3565-
flags: tuple[
3564+
flags: _Flags[
35663565
Literal[
35673566
"ignoreslopes",
35683567
"ignoreextrema",
@@ -3574,7 +3573,6 @@ class glyph:
35743573
"setstarttoextremum",
35753574
"removesingletonpoints",
35763575
],
3577-
...,
35783576
] = (),
35793577
tan_bounds: float | None = None,
35803578
linefixup: float | None = None,
@@ -3695,7 +3693,7 @@ class glyph:
36953693
def transform(
36963694
self,
36973695
matrix: tuple[float, float, float, float, float, float],
3698-
flags: tuple[Literal["partialRefs", "round"], ...] = (),
3696+
flags: _Flags[Literal["partialRefs", "round"]] = (),
36993697
) -> Self:
37003698
"""
37013699
Transforms the glyph by the matrix. The optional flags argument should be a
@@ -3872,8 +3870,8 @@ class selection:
38723870
*args: str
38733871
| int
38743872
| glyph
3875-
| tuple[
3876-
Literal["unicode", "encoding", "more", "less", "singletons", "ranges"], ...
3873+
| _Flags[
3874+
Literal["unicode", "encoding", "more", "less", "singletons", "ranges"],
38773875
],
38783876
) -> Self:
38793877
"""
@@ -4688,13 +4686,13 @@ class font:
46884686
gasp: tuple[
46894687
tuple[
46904688
int,
4691-
tuple[
4689+
_Flags[
46924690
Literal[
46934691
"gridfit", "antialias", "symmetric-smoothing", "gridfit+smoothing"
46944692
],
4695-
...,
46964693
],
4697-
]
4694+
],
4695+
...,
46984696
]
46994697
"""
47004698
Returns a tuple of all gasp table entries. Each item in the tuple is itself
@@ -6013,7 +6011,7 @@ class font:
60136011
self,
60146012
other_font: font,
60156013
filename: str,
6016-
flags_tuple: tuple[
6014+
flags: _Flags[
60176015
Literal[
60186016
"outlines",
60196017
"outlines-exactly",
@@ -6027,7 +6025,6 @@ class font:
60276025
"add-outlines",
60286026
"create-glyphs",
60296027
],
6030-
...,
60316028
],
60326029
) -> int:
60336030
"""
@@ -6123,7 +6120,7 @@ class font:
61236120
self,
61246121
contour: contour | layer,
61256122
error_bound: float = 0.01,
6126-
search_flags: tuple[Literal["reverse", "flips", "rotate", "scale"], ...] = (
6123+
search_flags: _Flags[Literal["reverse", "flips", "rotate", "scale"]] = (
61276124
"reverse",
61286125
"flips",
61296126
),
@@ -6168,7 +6165,7 @@ class font:
61686165
filename: str,
61696166
*,
61706167
bitmap_type: str | None = None,
6171-
flags: tuple[
6168+
flags: _Flags[
61726169
Literal[
61736170
"afm",
61746171
"pfm",
@@ -6196,7 +6193,6 @@ class font:
61966193
"PfEd-background",
61976194
"symbol",
61986195
],
6199-
...,
62006196
] = (),
62016197
bitmap_resolution: int | None = None,
62026198
subfont_directory: str | None = None,
@@ -6323,7 +6319,7 @@ class font:
63236319
filename: str,
63246320
others: Sequence[font] | font | None,
63256321
*,
6326-
flags: tuple[
6322+
flags: _Flags[
63276323
Literal[
63286324
"afm",
63296325
"pfm",
@@ -6339,6 +6335,7 @@ class font:
63396335
"dummy-dsig",
63406336
"no-FFTM-table",
63416337
"TeX-table",
6338+
"no-mac-names",
63426339
"round",
63436340
"no-hints",
63446341
"no-flex",
@@ -6350,9 +6347,8 @@ class font:
63506347
"PfEd-background",
63516348
"symbol",
63526349
],
6353-
...,
63546350
] = (),
6355-
ttcflags: tuple[Literal["merge", "cff"], ...] = (),
6351+
ttcflags: _Flags[Literal["merge", "cff"]] = (),
63566352
namelist: str | None = None,
63576353
layer: str | int | None = None,
63586354
) -> Self:
@@ -7038,7 +7034,7 @@ class font:
70387034
def simplify(
70397035
self,
70407036
error_bound: float | None = None,
7041-
flags: tuple[
7037+
flags: _Flags[
70427038
Literal[
70437039
"ignoreslopes",
70447040
"ignoreextrema",
@@ -7050,7 +7046,6 @@ class font:
70507046
"setstarttoextremum",
70517047
"removesingletonpoints",
70527048
],
7053-
...,
70547049
] = (),
70557050
tan_bounds: float | None = None,
70567051
linefixup: float | None = None,
@@ -7155,11 +7150,10 @@ class font:
71557150
def transform(
71567151
self,
71577152
matrix: tuple[float, float, float, float, float, float],
7158-
flags: tuple[
7153+
flags: _Flags[
71597154
Literal[
71607155
"activeLayer", "guide", "noWidth", "round", "simplePos", "kernClasses"
71617156
],
7162-
...,
71637157
] = (),
71647158
) -> Self:
71657159
"""

0 commit comments

Comments
 (0)