@@ -4781,14 +4781,16 @@ def to_required(self):
4781
4781
for p in self .function .parameters .values ():
4782
4782
p .group = - p .group
4783
4783
4784
- def state_parameter (self , line ):
4785
- if self .parameter_continuation :
4786
- line = self .parameter_continuation + ' ' + line .lstrip ()
4787
- self .parameter_continuation = ''
4784
+ def state_parameter (self , line : str | None ) -> None :
4785
+ assert isinstance (self .function , Function )
4788
4786
4789
4787
if not self .valid_line (line ):
4790
4788
return
4791
4789
4790
+ if self .parameter_continuation :
4791
+ line = self .parameter_continuation + ' ' + line .lstrip ()
4792
+ self .parameter_continuation = ''
4793
+
4792
4794
assert self .indent .depth == 2
4793
4795
indent = self .indent .infer (line )
4794
4796
if indent == - 1 :
@@ -4839,6 +4841,7 @@ def state_parameter(self, line):
4839
4841
fields [0 ] = name
4840
4842
line = ' ' .join (fields )
4841
4843
4844
+ default : str | None
4842
4845
base , equals , default = line .rpartition ('=' )
4843
4846
if not equals :
4844
4847
base = default
@@ -4861,7 +4864,9 @@ def state_parameter(self, line):
4861
4864
if not module :
4862
4865
fail ("Function " + self .function .name + " has an invalid parameter declaration:\n \t " + line )
4863
4866
4864
- function_args = module .body [0 ].args
4867
+ function = module .body [0 ]
4868
+ assert isinstance (function , ast .FunctionDef )
4869
+ function_args = function .args
4865
4870
4866
4871
if len (function_args .args ) > 1 :
4867
4872
fail ("Function " + self .function .name + " has an invalid parameter declaration (comma?):\n \t " + line )
@@ -4884,6 +4889,7 @@ def state_parameter(self, line):
4884
4889
if self .parameter_state is ParamState .OPTIONAL :
4885
4890
fail (f"Can't have a parameter without a default ({ parameter_name !r} )\n "
4886
4891
"after a parameter with a default!" )
4892
+ value : Sentinels | Null
4887
4893
if is_vararg :
4888
4894
value = NULL
4889
4895
kwargs .setdefault ('c_default' , "NULL" )
@@ -4946,8 +4952,11 @@ def bad_node(self, node):
4946
4952
if bad :
4947
4953
fail ("Unsupported expression as default value: " + repr (default ))
4948
4954
4949
- expr = module .body [0 ].value
4955
+ assignment = module .body [0 ]
4956
+ assert isinstance (assignment , ast .Assign )
4957
+ expr = assignment .value
4950
4958
# mild hack: explicitly support NULL as a default value
4959
+ c_default : str | None
4951
4960
if isinstance (expr , ast .Name ) and expr .id == 'NULL' :
4952
4961
value = NULL
4953
4962
py_default = '<unrepresentable>'
@@ -4964,7 +4973,7 @@ def bad_node(self, node):
4964
4973
value = unknown
4965
4974
elif isinstance (expr , ast .Attribute ):
4966
4975
a = []
4967
- n = expr
4976
+ n : ast . expr | ast . Attribute = expr
4968
4977
while isinstance (n , ast .Attribute ):
4969
4978
a .append (n .attr )
4970
4979
n = n .value
@@ -4984,7 +4993,7 @@ def bad_node(self, node):
4984
4993
else :
4985
4994
value = ast .literal_eval (expr )
4986
4995
py_default = repr (value )
4987
- if isinstance (value , (bool , None . __class__ )):
4996
+ if isinstance (value , (bool , NoneType )):
4988
4997
c_default = "Py_" + py_default
4989
4998
elif isinstance (value , str ):
4990
4999
c_default = c_repr (value )
@@ -5011,6 +5020,7 @@ def bad_node(self, node):
5011
5020
# but the parameter object gets the python name
5012
5021
converter = dict [name ](c_name or parameter_name , parameter_name , self .function , value , ** kwargs )
5013
5022
5023
+ kind : inspect ._ParameterKind
5014
5024
if is_vararg :
5015
5025
kind = inspect .Parameter .VAR_POSITIONAL
5016
5026
elif self .keyword_only :
@@ -5130,7 +5140,7 @@ def parse_special_symbol(self, symbol):
5130
5140
fail ("Function " + self .function .name + " mixes keyword-only and positional-only parameters, which is unsupported." )
5131
5141
p .kind = inspect .Parameter .POSITIONAL_ONLY
5132
5142
5133
- def state_parameter_docstring_start (self , line : str ) -> None :
5143
+ def state_parameter_docstring_start (self , line : str | None ) -> None :
5134
5144
self .parameter_docstring_indent = len (self .indent .margin )
5135
5145
assert self .indent .depth == 3
5136
5146
return self .next (self .state_parameter_docstring , line )
0 commit comments