@@ -2229,7 +2229,12 @@ def _module_and_class(self, fields):
2229
2229
return module , cls
2230
2230
2231
2231
2232
- def parse_file (filename , * , verify = True , output = None ):
2232
+ def parse_file (
2233
+ filename : str ,
2234
+ * ,
2235
+ verify : bool = True ,
2236
+ output : str | None = None
2237
+ ) -> None :
2233
2238
if not output :
2234
2239
output = filename
2235
2240
@@ -2261,7 +2266,10 @@ def parse_file(filename, *, verify=True, output=None):
2261
2266
write_file (fn , data )
2262
2267
2263
2268
2264
- def compute_checksum (input , length = None ):
2269
+ def compute_checksum (
2270
+ input : str | None ,
2271
+ length : int | None = None
2272
+ ) -> str :
2265
2273
input = input or ''
2266
2274
s = hashlib .sha1 (input .encode ('utf-8' )).hexdigest ()
2267
2275
if length :
@@ -2272,44 +2280,61 @@ def compute_checksum(input, length=None):
2272
2280
2273
2281
2274
2282
class PythonParser :
2275
- def __init__ (self , clinic ) :
2283
+ def __init__ (self , clinic : Clinic ) -> None :
2276
2284
pass
2277
2285
2278
- def parse (self , block ) :
2286
+ def parse (self , block : Block ) -> None :
2279
2287
s = io .StringIO ()
2280
2288
with OverrideStdioWith (s ):
2281
2289
exec (block .input )
2282
2290
block .output = s .getvalue ()
2283
2291
2284
2292
2293
+ ModuleDict = dict [str , "Module" ]
2294
+
2285
2295
class Module :
2286
- def __init__ (self , name , module = None ):
2296
+ def __init__ (
2297
+ self ,
2298
+ name : str ,
2299
+ module = None
2300
+ ) -> None :
2287
2301
self .name = name
2288
2302
self .module = self .parent = module
2289
2303
2290
- self .modules = collections .OrderedDict ()
2291
- self .classes = collections .OrderedDict ()
2292
- self .functions = []
2304
+ self .modules : ModuleDict = collections .OrderedDict ()
2305
+ self .classes : ClassDict = collections .OrderedDict ()
2306
+ self .functions : list [ Function ] = []
2293
2307
2294
- def __repr__ (self ):
2308
+ def __repr__ (self ) -> str :
2295
2309
return "<clinic.Module " + repr (self .name ) + " at " + str (id (self )) + ">"
2296
2310
2311
+
2312
+ ClassDict = dict [str , "Class" ]
2313
+
2297
2314
class Class :
2298
- def __init__ (self , name , module = None , cls = None , typedef = None , type_object = None ):
2315
+ def __init__ (
2316
+ self ,
2317
+ name : str ,
2318
+ module : Module | None = None ,
2319
+ cls = None ,
2320
+ typedef : str | None = None ,
2321
+ type_object : str | None = None
2322
+ ) -> None :
2299
2323
self .name = name
2300
2324
self .module = module
2301
2325
self .cls = cls
2302
2326
self .typedef = typedef
2303
2327
self .type_object = type_object
2304
2328
self .parent = cls or module
2305
2329
2306
- self .classes = collections .OrderedDict ()
2307
- self .functions = []
2330
+ self .classes : ClassDict = collections .OrderedDict ()
2331
+ self .functions : list [ Function ] = []
2308
2332
2309
- def __repr__ (self ):
2333
+ def __repr__ (self ) -> str :
2310
2334
return "<clinic.Class " + repr (self .name ) + " at " + str (id (self )) + ">"
2311
2335
2312
- unsupported_special_methods = set ("""
2336
+
2337
+ unsupported_special_methods : set [str ] = set ("""
2313
2338
2314
2339
__abs__
2315
2340
__add__
0 commit comments