1313a table's length changes you need to rewrite the whole file anyway.
1414"""
1515
16+ from __future__ import annotations
17+
18+ from collections .abc import KeysView
1619from io import BytesIO
1720from types import SimpleNamespace
1821from fontTools .misc .textTools import Tag
@@ -84,7 +87,7 @@ def __init__(self, file, checkChecksums=0, fontNumber=-1):
8487
8588 if self .sfntVersion not in ("\x00 \x01 \x00 \x00 " , "OTTO" , "true" ):
8689 raise TTLibError ("Not a TrueType or OpenType font (bad sfntVersion)" )
87- tables = {}
90+ tables : dict [ Tag , DirectoryEntry ] = {}
8891 for i in range (self .numTables ):
8992 entry = self .DirectoryEntry ()
9093 entry .fromFile (self .file )
@@ -96,15 +99,15 @@ def __init__(self, file, checkChecksums=0, fontNumber=-1):
9699 if self .flavor == "woff" :
97100 self .flavorData = WOFFFlavorData (self )
98101
99- def has_key (self , tag ) :
102+ def has_key (self , tag : str | bytes ) -> bool :
100103 return tag in self .tables
101104
102105 __contains__ = has_key
103106
104- def keys (self ):
107+ def keys (self ) -> KeysView [ Tag ] :
105108 return self .tables .keys ()
106109
107- def __getitem__ (self , tag ) :
110+ def __getitem__ (self , tag : str | bytes ) -> bytes :
108111 """Fetch the raw table data."""
109112 entry = self .tables [Tag (tag )]
110113 data = entry .loadData (self .file )
@@ -122,10 +125,10 @@ def __getitem__(self, tag):
122125 log .warning ("bad checksum for '%s' table" , tag )
123126 return data
124127
125- def __delitem__ (self , tag ) :
128+ def __delitem__ (self , tag : str | bytes ) -> None :
126129 del self .tables [Tag (tag )]
127130
128- def close (self ):
131+ def close (self ) -> None :
129132 self .file .close ()
130133
131134 # We define custom __getstate__ and __setstate__ to make SFNTReader pickle-able
0 commit comments