29
29
30
30
from collections .abc import Callable
31
31
from types import FunctionType , NoneType
32
- from typing import Any , Final , NamedTuple , NoReturn , Literal , overload
32
+ from typing import (
33
+ Any ,
34
+ Final ,
35
+ Literal ,
36
+ NamedTuple ,
37
+ NoReturn ,
38
+ TypeGuard ,
39
+ overload ,
40
+ )
33
41
34
42
# TODO:
35
43
#
@@ -4471,17 +4479,20 @@ def parse(self, block: Block) -> None:
4471
4479
block .output = self .saved_output
4472
4480
4473
4481
@staticmethod
4474
- def ignore_line (line ):
4482
+ def valid_line (line : str | None ) -> TypeGuard [str ]:
4483
+ if line is None :
4484
+ return False
4485
+
4475
4486
# ignore comment-only lines
4476
4487
if line .lstrip ().startswith ('#' ):
4477
- return True
4488
+ return False
4478
4489
4479
4490
# Ignore empty lines too
4480
4491
# (but not in docstring sections!)
4481
4492
if not line .strip ():
4482
- return True
4493
+ return False
4483
4494
4484
- return False
4495
+ return True
4485
4496
4486
4497
@staticmethod
4487
4498
def calculate_indent (line : str ) -> int :
@@ -4497,9 +4508,9 @@ def next(
4497
4508
if line is not None :
4498
4509
self .state (line )
4499
4510
4500
- def state_dsl_start (self , line ) :
4511
+ def state_dsl_start (self , line : str | None ) -> None :
4501
4512
# self.block = self.ClinicOutputBlock(self)
4502
- if self .ignore_line (line ):
4513
+ if not self .valid_line (line ):
4503
4514
return
4504
4515
4505
4516
# is it a directive?
@@ -4716,8 +4727,8 @@ def state_modulename_name(self, line):
4716
4727
ps_start , ps_left_square_before , ps_group_before , ps_required , \
4717
4728
ps_optional , ps_group_after , ps_right_square_after = range (7 )
4718
4729
4719
- def state_parameters_start (self , line ) :
4720
- if self .ignore_line (line ):
4730
+ def state_parameters_start (self , line : str ) -> None :
4731
+ if not self .valid_line (line ):
4721
4732
return
4722
4733
4723
4734
# if this line is not indented, we have no parameters
@@ -4742,7 +4753,7 @@ def state_parameter(self, line):
4742
4753
line = self .parameter_continuation + ' ' + line .lstrip ()
4743
4754
self .parameter_continuation = ''
4744
4755
4745
- if self .ignore_line (line ):
4756
+ if not self .valid_line (line ):
4746
4757
return
4747
4758
4748
4759
assert self .indent .depth == 2
@@ -5075,7 +5086,7 @@ def parse_special_symbol(self, symbol):
5075
5086
fail ("Function " + self .function .name + " mixes keyword-only and positional-only parameters, which is unsupported." )
5076
5087
p .kind = inspect .Parameter .POSITIONAL_ONLY
5077
5088
5078
- def state_parameter_docstring_start (self , line ) :
5089
+ def state_parameter_docstring_start (self , line : str ) -> None :
5079
5090
self .parameter_docstring_indent = len (self .indent .margin )
5080
5091
assert self .indent .depth == 3
5081
5092
return self .next (self .state_parameter_docstring , line )
0 commit comments