@@ -818,12 +818,6 @@ def output_templates(
818
818
del parameters [0 ]
819
819
converters = [p .converter for p in parameters ]
820
820
821
- # Copy includes from parameters to Clinic
822
- for converter in converters :
823
- include = converter .include
824
- if include :
825
- clinic .add_include (include .filename , include .reason ,
826
- condition = include .condition )
827
821
if f .critical_section :
828
822
clinic .add_include ('pycore_critical_section.h' , 'Py_BEGIN_CRITICAL_SECTION()' )
829
823
has_option_groups = parameters and (parameters [0 ].group or parameters [- 1 ].group )
@@ -1367,6 +1361,13 @@ def parser_body(
1367
1361
declarations = declarations )
1368
1362
1369
1363
1364
+ # Copy includes from parameters to Clinic after parse_arg() has been
1365
+ # called above.
1366
+ for converter in converters :
1367
+ for include in converter .includes :
1368
+ clinic .add_include (include .filename , include .reason ,
1369
+ condition = include .condition )
1370
+
1370
1371
if new_or_init :
1371
1372
methoddef_define = ''
1372
1373
@@ -2988,7 +2989,6 @@ class CConverter(metaclass=CConverterAutoRegister):
2988
2989
# Only set by self_converter.
2989
2990
signature_name : str | None = None
2990
2991
2991
- include : Include | None = None
2992
2992
broken_limited_capi : bool = False
2993
2993
2994
2994
# keep in sync with self_converter.__init__!
@@ -3008,6 +3008,7 @@ def __init__(self,
3008
3008
self .name = ensure_legal_c_identifier (name )
3009
3009
self .py_name = py_name
3010
3010
self .unused = unused
3011
+ self .includes : list [Include ] = []
3011
3012
3012
3013
if default is not unspecified :
3013
3014
if (self .default_type
@@ -3263,8 +3264,7 @@ def bad_argument(self, displayname: str, expected: str, *, limited_capi: bool, e
3263
3264
else :
3264
3265
if expected_literal :
3265
3266
expected = f'"{ expected } "'
3266
- if clinic is not None :
3267
- clinic .add_include ('pycore_modsupport.h' , '_PyArg_BadArgument()' )
3267
+ self .add_include ('pycore_modsupport.h' , '_PyArg_BadArgument()' )
3268
3268
return f'_PyArg_BadArgument("{{{{name}}}}", "{ displayname } ", { expected } , {{argname}});'
3269
3269
3270
3270
def format_code (self , fmt : str , * ,
@@ -3336,9 +3336,8 @@ def parser_name(self) -> str:
3336
3336
3337
3337
def add_include (self , name : str , reason : str ,
3338
3338
* , condition : str | None = None ) -> None :
3339
- if self .include is not None :
3340
- raise ValueError ("a converter only supports a single include" )
3341
- self .include = Include (name , reason , condition )
3339
+ include = Include (name , reason , condition )
3340
+ self .includes .append (include )
3342
3341
3343
3342
type_checks = {
3344
3343
'&PyLong_Type' : ('PyLong_Check' , 'int' ),
0 commit comments