@@ -324,9 +324,9 @@ def version_splitter(s: str) -> tuple[int, ...]:
324
324
c -> -1
325
325
(This permits Python-style version strings such as "1.4b3".)
326
326
"""
327
- version = []
327
+ version : list [ int ] = []
328
328
accumulator : list [str ] = []
329
- def flush ():
329
+ def flush () -> None :
330
330
if not accumulator :
331
331
raise ValueError ('Unsupported version string: ' + repr (s ))
332
332
version .append (int ('' .join (accumulator )))
@@ -4201,8 +4201,10 @@ def dedent(self, line):
4201
4201
return line [indent :]
4202
4202
4203
4203
4204
+ StateKeeper = Callable [[str | None ], None ]
4205
+
4204
4206
class DSLParser :
4205
- def __init__ (self , clinic ) :
4207
+ def __init__ (self , clinic : Clinic ) -> None :
4206
4208
self .clinic = clinic
4207
4209
4208
4210
self .directives = {}
@@ -4219,9 +4221,9 @@ def __init__(self, clinic):
4219
4221
4220
4222
self .reset ()
4221
4223
4222
- def reset (self ):
4224
+ def reset (self ) -> None :
4223
4225
self .function = None
4224
- self .state = self .state_dsl_start
4226
+ self .state : StateKeeper = self .state_dsl_start
4225
4227
self .parameter_indent = None
4226
4228
self .keyword_only = False
4227
4229
self .positional_only = False
@@ -4234,12 +4236,12 @@ def reset(self):
4234
4236
self .parameter_continuation = ''
4235
4237
self .preserve_output = False
4236
4238
4237
- def directive_version (self , required ) :
4239
+ def directive_version (self , required : str ) -> None :
4238
4240
global version
4239
4241
if version_comparitor (version , required ) < 0 :
4240
4242
fail ("Insufficient Clinic version!\n Version: " + version + "\n Required: " + required )
4241
4243
4242
- def directive_module (self , name ) :
4244
+ def directive_module (self , name : str ) -> None :
4243
4245
fields = name .split ('.' )[:- 1 ]
4244
4246
module , cls = self .clinic ._module_and_class (fields )
4245
4247
if cls :
@@ -4252,9 +4254,13 @@ def directive_module(self, name):
4252
4254
module .modules [name ] = m
4253
4255
self .block .signatures .append (m )
4254
4256
4255
- def directive_class (self , name , typedef , type_object ):
4257
+ def directive_class (
4258
+ self ,
4259
+ name : str ,
4260
+ typedef : str ,
4261
+ type_object : str
4262
+ ) -> None :
4256
4263
fields = name .split ('.' )
4257
- parent = self
4258
4264
name = fields .pop ()
4259
4265
module , cls = self .clinic ._module_and_class (fields )
4260
4266
@@ -4266,7 +4272,7 @@ def directive_class(self, name, typedef, type_object):
4266
4272
parent .classes [name ] = c
4267
4273
self .block .signatures .append (c )
4268
4274
4269
- def directive_set (self , name , value ) :
4275
+ def directive_set (self , name : str , value : str ) -> None :
4270
4276
if name not in ("line_prefix" , "line_suffix" ):
4271
4277
fail ("unknown variable" , repr (name ))
4272
4278
@@ -4277,7 +4283,12 @@ def directive_set(self, name, value):
4277
4283
4278
4284
self .clinic .__dict__ [name ] = value
4279
4285
4280
- def directive_destination (self , name , command , * args ):
4286
+ def directive_destination (
4287
+ self ,
4288
+ name : str ,
4289
+ command : str ,
4290
+ * args
4291
+ ) -> None :
4281
4292
if command == 'new' :
4282
4293
self .clinic .add_destination (name , * args )
4283
4294
return
@@ -4287,7 +4298,11 @@ def directive_destination(self, name, command, *args):
4287
4298
fail ("unknown destination command" , repr (command ))
4288
4299
4289
4300
4290
- def directive_output (self , command_or_name , destination = '' ):
4301
+ def directive_output (
4302
+ self ,
4303
+ command_or_name : str ,
4304
+ destination : str = ''
4305
+ ) -> None :
4291
4306
fd = self .clinic .destination_buffers
4292
4307
4293
4308
if command_or_name == "preset" :
@@ -4325,34 +4340,34 @@ def directive_output(self, command_or_name, destination=''):
4325
4340
fail ("Invalid command / destination name " + repr (command_or_name ) + ", must be one of:\n preset push pop print everything " + " " .join (fd ))
4326
4341
fd [command_or_name ] = d
4327
4342
4328
- def directive_dump (self , name ) :
4343
+ def directive_dump (self , name : str ) -> None :
4329
4344
self .block .output .append (self .clinic .get_destination (name ).dump ())
4330
4345
4331
- def directive_printout (self , * args ) :
4346
+ def directive_printout (self , * args : str ) -> None :
4332
4347
self .block .output .append (' ' .join (args ))
4333
4348
self .block .output .append ('\n ' )
4334
4349
4335
- def directive_preserve (self ):
4350
+ def directive_preserve (self ) -> None :
4336
4351
if self .preserve_output :
4337
4352
fail ("Can't have preserve twice in one block!" )
4338
4353
self .preserve_output = True
4339
4354
4340
- def at_classmethod (self ):
4355
+ def at_classmethod (self ) -> None :
4341
4356
if self .kind is not CALLABLE :
4342
4357
fail ("Can't set @classmethod, function is not a normal callable" )
4343
4358
self .kind = CLASS_METHOD
4344
4359
4345
- def at_staticmethod (self ):
4360
+ def at_staticmethod (self ) -> None :
4346
4361
if self .kind is not CALLABLE :
4347
4362
fail ("Can't set @staticmethod, function is not a normal callable" )
4348
4363
self .kind = STATIC_METHOD
4349
4364
4350
- def at_coexist (self ):
4365
+ def at_coexist (self ) -> None :
4351
4366
if self .coexist :
4352
4367
fail ("Called @coexist twice!" )
4353
4368
self .coexist = True
4354
4369
4355
- def parse (self , block ) :
4370
+ def parse (self , block : Block ) -> None :
4356
4371
self .reset ()
4357
4372
self .block = block
4358
4373
self .saved_output = self .block .output
@@ -4388,10 +4403,14 @@ def ignore_line(line):
4388
4403
return False
4389
4404
4390
4405
@staticmethod
4391
- def calculate_indent (line ) :
4406
+ def calculate_indent (line : str ) -> int :
4392
4407
return len (line ) - len (line .strip ())
4393
4408
4394
- def next (self , state , line = None ):
4409
+ def next (
4410
+ self ,
4411
+ state : StateKeeper ,
4412
+ line : str | None = None
4413
+ ) -> None :
4395
4414
# real_print(self.state.__name__, "->", state.__name__, ", line=", line)
4396
4415
self .state = state
4397
4416
if line is not None :
0 commit comments