45
45
NamedTuple ,
46
46
NoReturn ,
47
47
Protocol ,
48
- TypeGuard ,
49
48
TypeVar ,
50
49
cast ,
51
50
overload ,
@@ -4388,7 +4387,7 @@ def dedent(self, line: str) -> str:
4388
4387
return line [indent :]
4389
4388
4390
4389
4391
- StateKeeper = Callable [[str | None ], None ]
4390
+ StateKeeper = Callable [[str ], None ]
4392
4391
ConverterArgs = dict [str , Any ]
4393
4392
4394
4393
class ParamState (enum .IntEnum ):
@@ -4610,9 +4609,7 @@ def parse(self, block: Block) -> None:
4610
4609
fail ('Tab characters are illegal in the Clinic DSL.\n \t ' + repr (line ), line_number = block_start )
4611
4610
self .state (line )
4612
4611
4613
- self .next (self .state_terminal )
4614
- self .state (None )
4615
-
4612
+ self .do_post_block_processing_cleanup ()
4616
4613
block .output .extend (self .clinic .language .render (self .clinic , block .signatures ))
4617
4614
4618
4615
if self .preserve_output :
@@ -4621,10 +4618,7 @@ def parse(self, block: Block) -> None:
4621
4618
block .output = self .saved_output
4622
4619
4623
4620
@staticmethod
4624
- def valid_line (line : str | None ) -> TypeGuard [str ]:
4625
- if line is None :
4626
- return False
4627
-
4621
+ def valid_line (line : str ) -> bool :
4628
4622
# ignore comment-only lines
4629
4623
if line .lstrip ().startswith ('#' ):
4630
4624
return False
@@ -4650,7 +4644,7 @@ def next(
4650
4644
if line is not None :
4651
4645
self .state (line )
4652
4646
4653
- def state_dsl_start (self , line : str | None ) -> None :
4647
+ def state_dsl_start (self , line : str ) -> None :
4654
4648
# self.block = self.ClinicOutputBlock(self)
4655
4649
if not self .valid_line (line ):
4656
4650
return
@@ -4668,7 +4662,7 @@ def state_dsl_start(self, line: str | None) -> None:
4668
4662
4669
4663
self .next (self .state_modulename_name , line )
4670
4664
4671
- def state_modulename_name (self , line : str | None ) -> None :
4665
+ def state_modulename_name (self , line : str ) -> None :
4672
4666
# looking for declaration, which establishes the leftmost column
4673
4667
# line should be
4674
4668
# modulename.fnname [as c_basename] [-> return annotation]
@@ -4857,7 +4851,7 @@ def state_modulename_name(self, line: str | None) -> None:
4857
4851
# separate boolean state variables.) The states are defined in the
4858
4852
# ParamState class.
4859
4853
4860
- def state_parameters_start (self , line : str | None ) -> None :
4854
+ def state_parameters_start (self , line : str ) -> None :
4861
4855
if not self .valid_line (line ):
4862
4856
return
4863
4857
@@ -4879,7 +4873,7 @@ def to_required(self) -> None:
4879
4873
for p in self .function .parameters .values ():
4880
4874
p .group = - p .group
4881
4875
4882
- def state_parameter (self , line : str | None ) -> None :
4876
+ def state_parameter (self , line : str ) -> None :
4883
4877
assert isinstance (self .function , Function )
4884
4878
4885
4879
if not self .valid_line (line ):
@@ -5262,7 +5256,7 @@ def parse_slash(self, function: Function) -> None:
5262
5256
"positional-only parameters, which is unsupported." )
5263
5257
p .kind = inspect .Parameter .POSITIONAL_ONLY
5264
5258
5265
- def state_parameter_docstring_start (self , line : str | None ) -> None :
5259
+ def state_parameter_docstring_start (self , line : str ) -> None :
5266
5260
assert self .indent .margin is not None , "self.margin.infer() has not yet been called to set the margin"
5267
5261
self .parameter_docstring_indent = len (self .indent .margin )
5268
5262
assert self .indent .depth == 3
@@ -5271,9 +5265,7 @@ def state_parameter_docstring_start(self, line: str | None) -> None:
5271
5265
# every line of the docstring must start with at least F spaces,
5272
5266
# where F > P.
5273
5267
# these F spaces will be stripped.
5274
- def state_parameter_docstring (self , line : str | None ) -> None :
5275
- assert line is not None
5276
-
5268
+ def state_parameter_docstring (self , line : str ) -> None :
5277
5269
stripped = line .strip ()
5278
5270
if stripped .startswith ('#' ):
5279
5271
return
@@ -5301,9 +5293,8 @@ def state_parameter_docstring(self, line: str | None) -> None:
5301
5293
last_parameter .docstring = new_docstring
5302
5294
5303
5295
# the final stanza of the DSL is the docstring.
5304
- def state_function_docstring (self , line : str | None ) -> None :
5296
+ def state_function_docstring (self , line : str ) -> None :
5305
5297
assert self .function is not None
5306
- assert line is not None
5307
5298
5308
5299
if self .group :
5309
5300
fail ("Function " + self .function .name + " has a ] without a matching [." )
@@ -5572,12 +5563,10 @@ def add_parameter(text: str) -> None:
5572
5563
5573
5564
return docstring
5574
5565
5575
- def state_terminal (self , line : str | None ) -> None :
5566
+ def do_post_block_processing_cleanup (self ) -> None :
5576
5567
"""
5577
5568
Called when processing the block is done.
5578
5569
"""
5579
- assert not line
5580
-
5581
5570
if not self .function :
5582
5571
return
5583
5572
0 commit comments