@@ -1432,67 +1432,64 @@ def parser_body(
1432
1432
deprecated_keywords [i ] = p
1433
1433
1434
1434
has_optional_kw = (max (pos_only , min_pos ) + min_kw_only < len (converters ) - int (vararg != NO_VARARG ))
1435
- if vararg == NO_VARARG :
1436
- # FIXME: refactor the code to not declare args_declaration
1437
- # if limited_capi is true
1438
- if not limited_capi :
1439
- clinic .add_include ('pycore_modsupport.h' ,
1440
- '_PyArg_UnpackKeywords()' )
1441
- args_declaration = "_PyArg_UnpackKeywords" , "%s, %s, %s" % (
1442
- min_pos ,
1443
- max_pos ,
1444
- min_kw_only
1445
- )
1446
- nargs = "nargs"
1447
- else :
1448
- if not limited_capi :
1449
- clinic .add_include ('pycore_modsupport.h' ,
1450
- '_PyArg_UnpackKeywordsWithVararg()' )
1451
- args_declaration = "_PyArg_UnpackKeywordsWithVararg" , "%s, %s, %s, %s" % (
1452
- min_pos ,
1453
- max_pos ,
1454
- min_kw_only ,
1455
- vararg
1456
- )
1457
- nargs = f"Py_MIN(nargs, { max_pos } )" if max_pos else "0"
1458
1435
1459
1436
if limited_capi :
1460
1437
parser_code = None
1461
1438
fastcall = False
1462
-
1463
- elif fastcall :
1464
- flags = "METH_FASTCALL|METH_KEYWORDS"
1465
- parser_prototype = self .PARSER_PROTOTYPE_FASTCALL_KEYWORDS
1466
- argname_fmt = 'args[%d]'
1467
- declarations = declare_parser (f , clinic = clinic ,
1468
- limited_capi = clinic .limited_capi )
1469
- declarations += "\n PyObject *argsbuf[%s];" % len (converters )
1470
- if has_optional_kw :
1471
- declarations += "\n Py_ssize_t noptargs = %s + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - %d;" % (nargs , min_pos + min_kw_only )
1472
- parser_code = [normalize_snippet ("""
1473
- args = %s(args, nargs, NULL, kwnames, &_parser, %s, argsbuf);
1474
- if (!args) {{
1475
- goto exit;
1476
- }}
1477
- """ % args_declaration , indent = 4 )]
1478
1439
else :
1479
- # positional-or-keyword arguments
1480
- flags = "METH_VARARGS|METH_KEYWORDS"
1481
- parser_prototype = self .PARSER_PROTOTYPE_KEYWORD
1482
- argname_fmt = 'fastargs[%d]'
1483
- declarations = declare_parser (f , clinic = clinic ,
1484
- limited_capi = clinic .limited_capi )
1485
- declarations += "\n PyObject *argsbuf[%s];" % len (converters )
1486
- declarations += "\n PyObject * const *fastargs;"
1487
- declarations += "\n Py_ssize_t nargs = PyTuple_GET_SIZE(args);"
1488
- if has_optional_kw :
1489
- declarations += "\n Py_ssize_t noptargs = %s + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - %d;" % (nargs , min_pos + min_kw_only )
1490
- parser_code = [normalize_snippet ("""
1491
- fastargs = %s(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, %s, argsbuf);
1492
- if (!fastargs) {{
1493
- goto exit;
1494
- }}
1495
- """ % args_declaration , indent = 4 )]
1440
+ if vararg == NO_VARARG :
1441
+ clinic .add_include ('pycore_modsupport.h' ,
1442
+ '_PyArg_UnpackKeywords()' )
1443
+ args_declaration = "_PyArg_UnpackKeywords" , "%s, %s, %s" % (
1444
+ min_pos ,
1445
+ max_pos ,
1446
+ min_kw_only
1447
+ )
1448
+ nargs = "nargs"
1449
+ else :
1450
+ clinic .add_include ('pycore_modsupport.h' ,
1451
+ '_PyArg_UnpackKeywordsWithVararg()' )
1452
+ args_declaration = "_PyArg_UnpackKeywordsWithVararg" , "%s, %s, %s, %s" % (
1453
+ min_pos ,
1454
+ max_pos ,
1455
+ min_kw_only ,
1456
+ vararg
1457
+ )
1458
+ nargs = f"Py_MIN(nargs, { max_pos } )" if max_pos else "0"
1459
+
1460
+ if fastcall :
1461
+ flags = "METH_FASTCALL|METH_KEYWORDS"
1462
+ parser_prototype = self .PARSER_PROTOTYPE_FASTCALL_KEYWORDS
1463
+ argname_fmt = 'args[%d]'
1464
+ declarations = declare_parser (f , clinic = clinic ,
1465
+ limited_capi = clinic .limited_capi )
1466
+ declarations += "\n PyObject *argsbuf[%s];" % len (converters )
1467
+ if has_optional_kw :
1468
+ declarations += "\n Py_ssize_t noptargs = %s + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - %d;" % (nargs , min_pos + min_kw_only )
1469
+ parser_code = [normalize_snippet ("""
1470
+ args = %s(args, nargs, NULL, kwnames, &_parser, %s, argsbuf);
1471
+ if (!args) {{
1472
+ goto exit;
1473
+ }}
1474
+ """ % args_declaration , indent = 4 )]
1475
+ else :
1476
+ # positional-or-keyword arguments
1477
+ flags = "METH_VARARGS|METH_KEYWORDS"
1478
+ parser_prototype = self .PARSER_PROTOTYPE_KEYWORD
1479
+ argname_fmt = 'fastargs[%d]'
1480
+ declarations = declare_parser (f , clinic = clinic ,
1481
+ limited_capi = clinic .limited_capi )
1482
+ declarations += "\n PyObject *argsbuf[%s];" % len (converters )
1483
+ declarations += "\n PyObject * const *fastargs;"
1484
+ declarations += "\n Py_ssize_t nargs = PyTuple_GET_SIZE(args);"
1485
+ if has_optional_kw :
1486
+ declarations += "\n Py_ssize_t noptargs = %s + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - %d;" % (nargs , min_pos + min_kw_only )
1487
+ parser_code = [normalize_snippet ("""
1488
+ fastargs = %s(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, %s, argsbuf);
1489
+ if (!fastargs) {{
1490
+ goto exit;
1491
+ }}
1492
+ """ % args_declaration , indent = 4 )]
1496
1493
1497
1494
if requires_defining_class :
1498
1495
flags = 'METH_METHOD|' + flags
0 commit comments