@@ -2950,12 +2950,18 @@ def parse_argument(self, args: list[str]) -> None:
2950
2950
# All the functions after here are intended as extension points.
2951
2951
#
2952
2952
2953
- def simple_declaration (self , by_reference = False , * , in_parser = False ):
2953
+ def simple_declaration (
2954
+ self ,
2955
+ by_reference : bool = False ,
2956
+ * ,
2957
+ in_parser : bool = False
2958
+ ) -> str :
2954
2959
"""
2955
2960
Computes the basic declaration of the variable.
2956
2961
Used in computing the prototype declaration and the
2957
2962
variable declaration.
2958
2963
"""
2964
+ assert isinstance (self .type , str )
2959
2965
prototype = [self .type ]
2960
2966
if by_reference or not self .type .endswith ('*' ):
2961
2967
prototype .append (" " )
@@ -2970,7 +2976,7 @@ def simple_declaration(self, by_reference=False, *, in_parser=False):
2970
2976
prototype .append (name )
2971
2977
return "" .join (prototype )
2972
2978
2973
- def declaration (self , * , in_parser = False ) -> str :
2979
+ def declaration (self , * , in_parser : bool = False ) -> str :
2974
2980
"""
2975
2981
The C statement to declare this variable.
2976
2982
"""
@@ -3579,9 +3585,9 @@ class object_converter(CConverter):
3579
3585
3580
3586
def converter_init (
3581
3587
self , * ,
3582
- converter = None ,
3583
- type = None ,
3584
- subclass_of = None
3588
+ converter : str | None = None ,
3589
+ type : str | None = None ,
3590
+ subclass_of : str | None = None
3585
3591
) -> None :
3586
3592
if converter :
3587
3593
if subclass_of :
@@ -3973,7 +3979,7 @@ class self_converter(CConverter):
3973
3979
type = None
3974
3980
format_unit = ''
3975
3981
3976
- def converter_init (self , * , type = None ) -> None :
3982
+ def converter_init (self , * , type : str | None = None ) -> None :
3977
3983
self .specified_type = type
3978
3984
3979
3985
def pre_render (self ):
@@ -4047,7 +4053,7 @@ def render(self, parameter, data):
4047
4053
assert data .impl_arguments [0 ] == self .name
4048
4054
data .impl_arguments [0 ] = '(' + self .type + ")" + data .impl_arguments [0 ]
4049
4055
4050
- def set_template_dict (self , template_dict ) :
4056
+ def set_template_dict (self , template_dict : TemplateDict ) -> None :
4051
4057
template_dict ['self_name' ] = self .name
4052
4058
template_dict ['self_type' ] = self .parser_type
4053
4059
kind = self .function .kind
@@ -4066,7 +4072,7 @@ def set_template_dict(self, template_dict):
4066
4072
line = f'{ type_check } &&\n '
4067
4073
template_dict ['self_type_check' ] = line
4068
4074
4069
- type_object = self . function . cls .type_object
4075
+ type_object = cls .type_object
4070
4076
type_ptr = f'PyTypeObject *base_tp = { type_object } ;'
4071
4077
template_dict ['base_type_ptr' ] = type_ptr
4072
4078
@@ -4276,11 +4282,11 @@ def eval_ast_expr(
4276
4282
4277
4283
4278
4284
class IndentStack :
4279
- def __init__ (self ):
4280
- self .indents = []
4281
- self .margin = None
4285
+ def __init__ (self ) -> None :
4286
+ self .indents : list [ int ] = []
4287
+ self .margin : str | None = None
4282
4288
4283
- def _ensure (self ):
4289
+ def _ensure (self ) -> None :
4284
4290
if not self .indents :
4285
4291
fail ('IndentStack expected indents, but none are defined.' )
4286
4292
@@ -4341,13 +4347,15 @@ def indent(self, line: str) -> str:
4341
4347
"""
4342
4348
Indents a line by the currently defined margin.
4343
4349
"""
4350
+ assert self .margin is not None , "Cannot call .indent() before calling .infer()"
4344
4351
return self .margin + line
4345
4352
4346
4353
def dedent (self , line : str ) -> str :
4347
4354
"""
4348
4355
Dedents a line by the currently defined margin.
4349
4356
(The inverse of 'indent'.)
4350
4357
"""
4358
+ assert self .margin is not None , "Cannot call .indent() before calling .infer()"
4351
4359
margin = self .margin
4352
4360
indent = self .indents [- 1 ]
4353
4361
if not line .startswith (margin ):
@@ -5232,6 +5240,7 @@ def parse_slash(self, function: Function) -> None:
5232
5240
p .kind = inspect .Parameter .POSITIONAL_ONLY
5233
5241
5234
5242
def state_parameter_docstring_start (self , line : str | None ) -> None :
5243
+ assert self .indent .margin is not None , "self.margin.infer() has not yet been called to set the margin"
5235
5244
self .parameter_docstring_indent = len (self .indent .margin )
5236
5245
assert self .indent .depth == 3
5237
5246
return self .next (self .state_parameter_docstring , line )
@@ -5534,7 +5543,7 @@ def add_parameter(text):
5534
5543
5535
5544
return docstring
5536
5545
5537
- def state_terminal (self , line ) :
5546
+ def state_terminal (self , line : str | None ) -> None :
5538
5547
"""
5539
5548
Called when processing the block is done.
5540
5549
"""
0 commit comments