@@ -2600,7 +2600,7 @@ class CConverter(metaclass=CConverterAutoRegister):
2600
2600
# Or the magic value "unknown" if this value is a cannot be evaluated
2601
2601
# at Argument-Clinic-preprocessing time (but is presumed to be valid
2602
2602
# at runtime).
2603
- default = unspecified
2603
+ default : bool | Unspecified = unspecified
2604
2604
2605
2605
# If not None, default must be isinstance() of this type.
2606
2606
# (You can also specify a tuple of types.)
@@ -2655,7 +2655,7 @@ class CConverter(metaclass=CConverterAutoRegister):
2655
2655
2656
2656
# What encoding do we want for this variable? Only used
2657
2657
# by format units starting with 'e'.
2658
- encoding = None
2658
+ encoding : str | None = None
2659
2659
2660
2660
# Should this object be required to be a subclass of a specific type?
2661
2661
# If not None, should be a string representing a pointer to a
@@ -2982,14 +2982,16 @@ def parser_name(self):
2982
2982
# note however that they will never be called with keyword-only parameters.
2983
2983
legacy_converters : ConverterDict = {}
2984
2984
2985
+ TypeSet = set [bltns .type [Any ]]
2986
+
2985
2987
2986
2988
class bool_converter (CConverter ):
2987
2989
type = 'int'
2988
2990
default_type = bool
2989
2991
format_unit = 'p'
2990
2992
c_ignored_default = '0'
2991
2993
2992
- def converter_init (self , * , accept = {object }):
2994
+ def converter_init (self , * , accept : TypeSet = {object }) -> None :
2993
2995
if accept == {int }:
2994
2996
self .format_unit = 'i'
2995
2997
elif accept != {object }:
@@ -3176,7 +3178,7 @@ class int_converter(CConverter):
3176
3178
format_unit = 'i'
3177
3179
c_ignored_default = "0"
3178
3180
3179
- def converter_init (self , * , accept = {int }, type = None ) -> None :
3181
+ def converter_init (self , * , accept : TypeSet = {int }, type = None ) -> None :
3180
3182
if accept == {str }:
3181
3183
self .format_unit = 'C'
3182
3184
elif accept != {int }:
@@ -3313,7 +3315,7 @@ class Py_ssize_t_converter(CConverter):
3313
3315
type = 'Py_ssize_t'
3314
3316
c_ignored_default = "0"
3315
3317
3316
- def converter_init (self , * , accept = {int }) -> None :
3318
+ def converter_init (self , * , accept : TypeSet = {int }) -> None :
3317
3319
if accept == {int }:
3318
3320
self .format_unit = 'n'
3319
3321
self .default_type = int
@@ -3344,7 +3346,7 @@ def parse_arg(self, argname: str, displayname: str) -> str:
3344
3346
class slice_index_converter (CConverter ):
3345
3347
type = 'Py_ssize_t'
3346
3348
3347
- def converter_init (self , * , accept = {int , NoneType }) -> None :
3349
+ def converter_init (self , * , accept : TypeSet = {int , NoneType }) -> None :
3348
3350
if accept == {int }:
3349
3351
self .converter = '_PyEval_SliceIndexNotNone'
3350
3352
elif accept == {int , NoneType }:
@@ -3447,7 +3449,12 @@ class object_converter(CConverter):
3447
3449
type = 'PyObject *'
3448
3450
format_unit = 'O'
3449
3451
3450
- def converter_init (self , * , converter = None , type = None , subclass_of = None ):
3452
+ def converter_init (
3453
+ self , * ,
3454
+ converter = None ,
3455
+ type = None ,
3456
+ subclass_of = None
3457
+ ) -> None :
3451
3458
if converter :
3452
3459
if subclass_of :
3453
3460
fail ("object: Cannot pass in both 'converter' and 'subclass_of'" )
@@ -3483,7 +3490,13 @@ class str_converter(CConverter):
3483
3490
default_type = (str , Null , NoneType )
3484
3491
format_unit = 's'
3485
3492
3486
- def converter_init (self , * , accept = {str }, encoding = None , zeroes = False ):
3493
+ def converter_init (
3494
+ self ,
3495
+ * ,
3496
+ accept : TypeSet = {str },
3497
+ encoding : str | None = None ,
3498
+ zeroes : bool = False
3499
+ ) -> None :
3487
3500
3488
3501
key = str_converter_key (accept , encoding , zeroes )
3489
3502
format_unit = str_converter_argument_map .get (key )
@@ -3561,7 +3574,14 @@ def parse_arg(self, argname: str, displayname: str) -> str:
3561
3574
# mapping from arguments to format unit *and* registers the
3562
3575
# legacy C converter for that format unit.
3563
3576
#
3564
- def r (format_unit , * , accept , encoding = False , zeroes = False ):
3577
+ ConverterKeywordDict = dict [str , TypeSet | bool ]
3578
+
3579
+ def r (format_unit : str ,
3580
+ * ,
3581
+ accept : TypeSet ,
3582
+ encoding : bool = False ,
3583
+ zeroes : bool = False
3584
+ ) -> None :
3565
3585
if not encoding and format_unit != 's' :
3566
3586
# add the legacy c converters here too.
3567
3587
#
@@ -3571,7 +3591,7 @@ def r(format_unit, *, accept, encoding=False, zeroes=False):
3571
3591
#
3572
3592
# also don't add the converter for 's' because
3573
3593
# the metaclass for CConverter adds it for us.
3574
- kwargs = {}
3594
+ kwargs : ConverterKeywordDict = {}
3575
3595
if accept != {str }:
3576
3596
kwargs ['accept' ] = accept
3577
3597
if zeroes :
@@ -3660,7 +3680,11 @@ class Py_UNICODE_converter(CConverter):
3660
3680
type = 'const Py_UNICODE *'
3661
3681
default_type = (str , Null , NoneType )
3662
3682
3663
- def converter_init (self , * , accept = {str }, zeroes : bool = False ) -> None :
3683
+ def converter_init (
3684
+ self , * ,
3685
+ accept : TypeSet = {str },
3686
+ zeroes : bool = False
3687
+ ) -> None :
3664
3688
format_unit = 'Z' if accept == {str , NoneType } else 'u'
3665
3689
if zeroes :
3666
3690
format_unit += '#'
@@ -3722,7 +3746,7 @@ class Py_buffer_converter(CConverter):
3722
3746
impl_by_reference = True
3723
3747
c_ignored_default = "{NULL, NULL}"
3724
3748
3725
- def converter_init (self , * , accept = {buffer }) -> None :
3749
+ def converter_init (self , * , accept : TypeSet = {buffer }) -> None :
3726
3750
if self .default not in (unspecified , None ):
3727
3751
fail ("The only legal default value for Py_buffer is None." )
3728
3752
0 commit comments