(self)
| 488 | return c.parse_var_keyword() |
| 489 | |
| 490 | def parse_pos_only(self) -> None: |
| 491 | if self.fastcall: |
| 492 | # positional-only, but no option groups |
| 493 | # we only need one call to _PyArg_ParseStack |
| 494 | |
| 495 | self.flags = "METH_FASTCALL" |
| 496 | self.parser_prototype = PARSER_PROTOTYPE_FASTCALL |
| 497 | nargs = 'nargs' |
| 498 | argname_fmt = 'args[%d]' |
| 499 | else: |
| 500 | # positional-only, but no option groups |
| 501 | # we only need one call to PyArg_ParseTuple |
| 502 | |
| 503 | self.flags = "METH_VARARGS" |
| 504 | self.parser_prototype = PARSER_PROTOTYPE_VARARGS |
| 505 | if self.limited_capi: |
| 506 | nargs = 'PyTuple_Size(args)' |
| 507 | argname_fmt = 'PyTuple_GetItem(args, %d)' |
| 508 | else: |
| 509 | nargs = 'PyTuple_GET_SIZE(args)' |
| 510 | argname_fmt = 'PyTuple_GET_ITEM(args, %d)' |
| 511 | |
| 512 | parser_code = [] |
| 513 | max_args = NO_VARARG if self.varpos else self.max_pos |
| 514 | if self.limited_capi: |
| 515 | if nargs != 'nargs': |
| 516 | nargs_def = f'Py_ssize_t nargs = {nargs};' |
| 517 | parser_code.append(libclinic.normalize_snippet(nargs_def, indent=4)) |
| 518 | nargs = 'nargs' |
| 519 | if self.min_pos == max_args: |
| 520 | pl = '' if self.min_pos == 1 else 's' |
| 521 | parser_code.append(libclinic.normalize_snippet(f""" |
| 522 | if ({nargs} != {self.min_pos}) {{{{ |
| 523 | PyErr_Format(PyExc_TypeError, "{{name}} expected {self.min_pos} argument{pl}, got %zd", {nargs}); |
| 524 | goto exit; |
| 525 | }}}} |
| 526 | """, |
| 527 | indent=4)) |
| 528 | else: |
| 529 | if self.min_pos: |
| 530 | pl = '' if self.min_pos == 1 else 's' |
| 531 | parser_code.append(libclinic.normalize_snippet(f""" |
| 532 | if ({nargs} < {self.min_pos}) {{{{ |
| 533 | PyErr_Format(PyExc_TypeError, "{{name}} expected at least {self.min_pos} argument{pl}, got %zd", {nargs}); |
| 534 | goto exit; |
| 535 | }}}} |
| 536 | """, |
| 537 | indent=4)) |
| 538 | if max_args != NO_VARARG: |
| 539 | pl = '' if max_args == 1 else 's' |
| 540 | parser_code.append(libclinic.normalize_snippet(f""" |
| 541 | if ({nargs} > {max_args}) {{{{ |
| 542 | PyErr_Format(PyExc_TypeError, "{{name}} expected at most {max_args} argument{pl}, got %zd", {nargs}); |
| 543 | goto exit; |
| 544 | }}}} |
| 545 | """, |
| 546 | indent=4)) |
| 547 | elif self.min_pos or max_args != NO_VARARG: |
no test coverage detected