2323 import libclinic
2424 from libclinic import ClinicError , unspecified , NULL , fail
2525 from libclinic .converters import (
26- int_converter , object_converter , str_converter , self_converter ,
27- Py_ssize_t_converter )
26+ int_converter , object_converter , str_converter , self_converter )
2827 from libclinic .function import (
2928 Module , Class , Function , FunctionKind , Parameter ,
3029 permute_optional_groups , permute_right_option_groups ,
@@ -860,13 +859,8 @@ def test_slot_with_parameters_and_return_type(self):
860859 # Slots which take arguments or return something else than an
861860 # object are not supported yet; check the machinery with them.
862861 slots = {
863- '__contains__' : (
864- SlotSpec (return_converter = 'int' ,
865- parameters = (object_converter ,)),
866- ),
867- '__bool__' : (
868- SlotSpec (return_converter = 'int' ),
869- ),
862+ '__contains__' : SlotSpec (return_type = 'int' ),
863+ '__bool__' : SlotSpec (return_type = 'int' ),
870864 }
871865 block = """
872866 /*[clinic input]
@@ -3357,65 +3351,38 @@ class Foo "FooObject *" ""
33573351 Foo.__next__
33583352 """ , signatures_in_block = 3 , function_index = 2 )
33593353 self .assertIs (function .kind , FunctionKind .SLOT )
3360- self .assertIs (function .slot , SLOTS ["__next__" ][ 0 ] )
3354+ self .assertIs (function .slot , SLOTS ["__next__" ])
33613355 self .assertEqual (function .c_basename , "Foo_next" )
33623356 self .assertEqual (function .return_converter .type , "PyObject *" )
33633357 self .assertEqual (list (function .parameters ), ["self" ])
33643358
33653359 def test_slot_parameters (self ):
3366- # __getitem__ is not supported yet: the parameters select the slot
3367- # (sq_item or mp_subscript).
3368- slots = (
3369- SlotSpec (return_converter = 'object' ,
3370- parameters = (Py_ssize_t_converter ,)),
3371- SlotSpec (return_converter = 'object' ,
3372- parameters = (object_converter ,)),
3373- )
3360+ # __getitem__ is not supported yet; its parameter gives the slot
3361+ # (Py_ssize_t for sq_item, object for mp_subscript) and is not parsed.
33743362 block = """
33753363 module foo
33763364 class Foo "FooObject *" ""
33773365 Foo.__getitem__
33783366 key: {converter}
33793367 /
33803368 """
3369+ errors = [
3370+ ("Foo.__getitem__\n key: object" ,
3371+ "The parameters of '__getitem__' must be positional-only" ),
3372+ ("Foo.__getitem__\n key: object = None\n /" ,
3373+ "The parameters of '__getitem__' cannot have a default value" ),
3374+ ]
33813375 supported = unsupported_special_methods - {'__getitem__' }
3382- with (mock .patch .dict (SLOTS , {'__getitem__' : slots }),
3376+ with (mock .patch .dict (SLOTS , {'__getitem__' : SlotSpec ( return_type = 'PyObject *' ) }),
33833377 mock .patch .object (libclinic .dsl_parser ,
33843378 'unsupported_special_methods' , supported )):
3385- for converter , slot in zip (( "Py_ssize_t" , "object" ), slots ) :
3379+ for converter in "Py_ssize_t" , "object" :
33863380 with self .subTest (converter = converter ):
33873381 function = self .parse_function (
33883382 block .format (converter = converter ),
33893383 signatures_in_block = 3 , function_index = 2 )
33903384 self .assertIs (function .kind , FunctionKind .SLOT )
3391- self .assertIs (function .slot , slot )
33923385 self .assertEqual (list (function .parameters ), ["self" , "key" ])
3393-
3394- def test_slot_parameter_errors (self ):
3395- # __setattr__ is not planned to be supported; its two slots
3396- # (tp_setattro and tp_setattr) make the error message list the
3397- # alternatives.
3398- slots = (
3399- SlotSpec (return_converter = 'int' ,
3400- parameters = (object_converter , object_converter )),
3401- SlotSpec (return_converter = 'int' ,
3402- parameters = (str_converter , object_converter )),
3403- )
3404- errors = [
3405- ("Foo.__setattr__" ,
3406- "'__setattr__' must declare (object, object) or (str, object); "
3407- "got ()" ),
3408- ("Foo.__setattr__\n name: int\n value: object\n /" ,
3409- "'__setattr__' must declare" ),
3410- ("Foo.__setattr__\n name: object\n value: object" ,
3411- "The parameters of '__setattr__' must be positional-only" ),
3412- ("Foo.__setattr__\n name: object\n value: object = None\n /" ,
3413- "The parameters of '__setattr__' cannot have a default value" ),
3414- ]
3415- supported = unsupported_special_methods - {'__setattr__' }
3416- with (mock .patch .dict (SLOTS , {'__setattr__' : slots }),
3417- mock .patch .object (libclinic .dsl_parser ,
3418- 'unsupported_special_methods' , supported )):
34193386 for body , err in errors :
34203387 with self .subTest (block = body ):
34213388 body = 'class Foo "FooObject *" "&Foo_Type"\n ' + body
@@ -3433,8 +3400,6 @@ def test_slot_errors(self):
34333400 "@coexist cannot be applied to '__next__'" ),
34343401 ("@vectorcall\n Foo.__next__" ,
34353402 "@vectorcall can only be used with __init__ and __new__" ),
3436- ("Foo.__next__\n a: int" ,
3437- "'__next__' methods cannot define parameters" ),
34383403 ("Foo.__next__ -> int" ,
34393404 "'Foo.__next__' cannot define a return type" ),
34403405 ("Foo.__next__\n \n Return the next item." ,
0 commit comments