4
4
# Copyright 2012-2013 by Larry Hastings.
5
5
# Licensed to the PSF under a contributor agreement.
6
6
#
7
+ from __future__ import annotations
7
8
8
9
import abc
9
10
import ast
@@ -2448,7 +2449,7 @@ def __init__(
2448
2449
cls : Class | None = None ,
2449
2450
c_basename : str | None = None ,
2450
2451
full_name : str | None = None ,
2451
- return_converter : ReturnConverterType ,
2452
+ return_converter : CReturnConverter ,
2452
2453
return_annotation = inspect .Signature .empty ,
2453
2454
docstring : str | None = None ,
2454
2455
kind : str = CALLABLE ,
@@ -2467,7 +2468,7 @@ def __init__(
2467
2468
self .docstring = docstring or ''
2468
2469
self .kind = kind
2469
2470
self .coexist = coexist
2470
- self .self_converter = None
2471
+ self .self_converter : self_converter | None = None
2471
2472
# docstring_only means "don't generate a machine-readable
2472
2473
# signature, just a normal docstring". it's True for
2473
2474
# functions with optional groups because we can't represent
@@ -2531,7 +2532,7 @@ class Parameter:
2531
2532
def __init__ (
2532
2533
self ,
2533
2534
name : str ,
2534
- kind : str ,
2535
+ kind : inspect . _ParameterKind ,
2535
2536
* ,
2536
2537
default = inspect .Parameter .empty ,
2537
2538
function : Function ,
@@ -4539,7 +4540,7 @@ def state_dsl_start(self, line: str | None) -> None:
4539
4540
4540
4541
self .next (self .state_modulename_name , line )
4541
4542
4542
- def state_modulename_name (self , line ) :
4543
+ def state_modulename_name (self , line : str | None ) -> None :
4543
4544
# looking for declaration, which establishes the leftmost column
4544
4545
# line should be
4545
4546
# modulename.fnname [as c_basename] [-> return annotation]
@@ -4556,13 +4557,14 @@ def state_modulename_name(self, line):
4556
4557
# this line is permitted to start with whitespace.
4557
4558
# we'll call this number of spaces F (for "function").
4558
4559
4559
- if not line . strip ( ):
4560
+ if not self . valid_line ( line ):
4560
4561
return
4561
4562
4562
4563
self .indent .infer (line )
4563
4564
4564
4565
# are we cloning?
4565
4566
before , equals , existing = line .rpartition ('=' )
4567
+ c_basename : str | None
4566
4568
if equals :
4567
4569
full_name , _ , c_basename = before .partition (' as ' )
4568
4570
full_name = full_name .strip ()
@@ -4665,8 +4667,9 @@ def state_modulename_name(self, line):
4665
4667
if cls and type == "PyObject *" :
4666
4668
kwargs ['type' ] = cls .typedef
4667
4669
sc = self .function .self_converter = self_converter (name , name , self .function , ** kwargs )
4668
- p_self = Parameter (sc .name , inspect .Parameter .POSITIONAL_ONLY , function = self .function , converter = sc )
4669
- self .function .parameters [sc .name ] = p_self
4670
+ p_self = Parameter (name , inspect .Parameter .POSITIONAL_ONLY ,
4671
+ function = self .function , converter = sc )
4672
+ self .function .parameters [name ] = p_self
4670
4673
4671
4674
(cls or module ).functions .append (self .function )
4672
4675
self .next (self .state_parameters_start )
@@ -4740,7 +4743,7 @@ def state_modulename_name(self, line):
4740
4743
ps_start , ps_left_square_before , ps_group_before , ps_required , \
4741
4744
ps_optional , ps_group_after , ps_right_square_after = range (7 )
4742
4745
4743
- def state_parameters_start (self , line : str ) -> None :
4746
+ def state_parameters_start (self , line : str | None ) -> None :
4744
4747
if not self .valid_line (line ):
4745
4748
return
4746
4749
0 commit comments