11# -*- coding: utf-8 -*-
2+ from __future__ import annotations
3+
24from fontTools .misc import sstruct
35from fontTools .misc .textTools import (
46 bytechr ,
@@ -63,7 +65,7 @@ def decompile(self, data, ttFont):
6365 )
6466 stringData = data [stringOffset :]
6567 data = data [6 :]
66- self .names = []
68+ self .names : list [ NameRecord ] = []
6769 for i in range (n ):
6870 if len (data ) < 12 :
6971 log .error ("skipping malformed name record #%d" , i )
@@ -112,7 +114,9 @@ def fromXML(self, name, attrs, content, ttFont):
112114 self .names .append (name )
113115 name .fromXML (name , attrs , content , ttFont )
114116
115- def getName (self , nameID , platformID , platEncID , langID = None ):
117+ def getName (
118+ self , nameID : int , platformID : int , platEncID : int , langID : int | None = None
119+ ) -> "NameRecord | None" :
116120 for namerecord in self .names :
117121 if (
118122 namerecord .nameID == nameID
@@ -123,8 +127,9 @@ def getName(self, nameID, platformID, platEncID, langID=None):
123127 return namerecord
124128 return None # not found
125129
126- def getDebugName (self , nameID ):
127- englishName = someName = None
130+ def getDebugName (self , nameID : int ) -> str | None :
131+ englishName : str | None = None
132+ someName : str | None = None
128133 for name in self .names :
129134 if name .nameID != nameID :
130135 continue
@@ -513,7 +518,7 @@ def isUnicode(self):
513518 self .platformID == 3 and self .platEncID in [0 , 1 , 10 ]
514519 )
515520
516- def toUnicode (self , errors = "strict" ):
521+ def toUnicode (self , errors : str = "strict" ) -> str :
517522 """
518523 If self.string is a Unicode string, return it; otherwise try decoding the
519524 bytes in self.string to a Unicode string using the encoding of this
@@ -533,7 +538,7 @@ def toUnicode(self, errors="strict"):
533538 and saving it back will not change them.
534539 """
535540
536- def isascii (b ) :
541+ def isascii (b : int ) -> bool :
537542 return (b >= 0x20 and b <= 0x7E ) or b in [0x09 , 0x0A , 0x0D ]
538543
539544 encoding = self .getEncoding ()
0 commit comments