| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3542,6 +3542,17 @@ def test_my_int_func(self): | |||
| 3542 | 3542 | with self.assertRaises(TypeError): | |
| 3543 | 3543 | _testclinic_limited.my_int_func("xyz") | |
| 3544 | 3544 | ||
| 3545 | + def test_my_int_sum(self): | ||
| 3546 | + with self.assertRaises(TypeError): | ||
| 3547 | + _testclinic_limited.my_int_sum() | ||
| 3548 | + with self.assertRaises(TypeError): | ||
| 3549 | + _testclinic_limited.my_int_sum(1) | ||
| 3550 | + self.assertEqual(_testclinic_limited.my_int_sum(1, 2), 3) | ||
| 3551 | + with self.assertRaises(TypeError): | ||
| 3552 | + _testclinic_limited.my_int_sum(1.0, 2) | ||
| 3553 | + with self.assertRaises(TypeError): | ||
| 3554 | + _testclinic_limited.my_int_sum(1, "str") | ||
| 3555 | + | ||
| 3545 | 3556 | ||
| 3546 | 3557 | ||
| 3547 | 3558 | class PermutationTests(unittest.TestCase): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -45,9 +45,27 @@ my_int_func_impl(PyObject *module, int arg) | |||
| 45 | 45 | } | |
| 46 | 46 | ||
| 47 | 47 | ||
| 48 | + /*[clinic input] | ||
| 49 | + my_int_sum -> int | ||
| 50 | + | ||
| 51 | + x: int | ||
| 52 | + y: int | ||
| 53 | + / | ||
| 54 | + | ||
| 55 | + [clinic start generated code]*/ | ||
| 56 | + | ||
| 57 | + static int | ||
| 58 | + my_int_sum_impl(PyObject *module, int x, int y) | ||
| 59 | + /*[clinic end generated code: output=3e52db9ab5f37e2f input=0edb6796813bf2d3]*/ | ||
| 60 | + { | ||
| 61 | + return x + y; | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + | ||
| 48 | 65 | static PyMethodDef tester_methods[] = { | |
| 49 | 66 | TEST_EMPTY_FUNCTION_METHODDEF | |
| 50 | 67 | MY_INT_FUNC_METHODDEF | |
| 68 | + MY_INT_SUM_METHODDEF | ||
| 51 | 69 | {NULL, NULL} | |
| 52 | 70 | }; | |
| 53 | 71 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -78,6 +78,7 @@ | |||
| 78 | 78 | "noptargs", | |
| 79 | 79 | "return_value", | |
| 80 | 80 | } | |
| 81 | + LIMITED_CAPI_REGEX = re.compile(r'#define +Py_LIMITED_API') | ||
| 81 | 82 | ||
| 82 | 83 | ||
| 83 | 84 | class Sentinels(enum.Enum): | |
@@ -1249,6 +1250,22 @@ def parser_body( | |||
| 1249 | 1250 | parser_prototype = self.PARSER_PROTOTYPE_VARARGS | |
| 1250 | 1251 | parser_definition = parser_body(parser_prototype, ' {option_group_parsing}') | |
| 1251 | 1252 | ||
| 1253 | + elif not requires_defining_class and pos_only == len(parameters) - pseudo_args and clinic.limited_capi: | ||
| 1254 | + # positional-only for the limited C API | ||
| 1255 | + flags = "METH_VARARGS" | ||
| 1256 | + | ||
| 1257 | + parser_prototype = self.PARSER_PROTOTYPE_VARARGS | ||
| 1258 | + parser_code = [normalize_snippet(""" | ||
| 1259 | + if (!PyArg_ParseTuple(args, "{format_units}:{name}", | ||
| 1260 | + {parse_arguments})) | ||
| 1261 | + goto exit; | ||
| 1262 | + """, indent=4)] | ||
| 1263 | + argname_fmt = 'args[%d]' | ||
| 1264 | + declarations = "" | ||
| 1265 | + | ||
| 1266 | + parser_definition = parser_body(parser_prototype, *parser_code, | ||
| 1267 | + declarations=declarations) | ||
| 1268 | + | ||
| 1252 | 1269 | elif not requires_defining_class and pos_only == len(parameters) - pseudo_args: | |
| 1253 | 1270 | if not new_or_init: | |
| 1254 | 1271 | # positional-only, but no option groups | |
@@ -2581,10 +2598,6 @@ def parse_file( | |||
| 2581 | 2598 | ) -> None: | |
| 2582 | 2599 | verify = not ns.force | |
| 2583 | 2600 | limited_capi = ns.limited_capi | |
| 2584 | - # XXX Temporary solution | ||
| 2585 | - if os.path.basename(filename) == '_testclinic_limited.c': | ||
| 2586 | - print(f"{filename} uses limited C API") | ||
| 2587 | - limited_capi = True | ||
| 2588 | 2601 | if not output: | |
| 2589 | 2602 | output = filename | |
| 2590 | 2603 | ||
@@ -2605,6 +2618,9 @@ def parse_file( | |||
| 2605 | 2618 | if not find_start_re.search(raw): | |
| 2606 | 2619 | return | |
| 2607 | 2620 | ||
| 2621 | + if LIMITED_CAPI_REGEX.search(raw): | ||
| 2622 | + limited_capi = True | ||
| 2623 | + | ||
| 2608 | 2624 | assert isinstance(language, CLanguage) | |
| 2609 | 2625 | clinic = Clinic(language, | |
| 2610 | 2626 | verify=verify, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments