blob: 80c70389ab30d6fe6c9d2d6da2c70bffeb60866b [file] [log] [blame]
Miss Islington (bot)8a37e8c2021-07-26 12:02:58 -07001// types.UnionType -- used to represent e.g. Union[int, str], int | str
Maggie Moss1b4552c2020-09-09 13:23:24 -07002#include "Python.h"
Miss Islington (bot)08561342021-07-03 06:33:16 -07003#include "pycore_object.h" // _PyObject_GC_TRACK/UNTRACK
Maggie Moss1b4552c2020-09-09 13:23:24 -07004#include "pycore_unionobject.h"
5#include "structmember.h"
6
7
Miss Islington (bot)03aad302021-07-17 14:10:21 -07008static PyObject *make_union(PyObject *);
9
10
Maggie Moss1b4552c2020-09-09 13:23:24 -070011typedef struct {
12 PyObject_HEAD
13 PyObject *args;
Serhiy Storchaka2d055ce2021-07-17 22:14:57 +030014 PyObject *parameters;
Maggie Moss1b4552c2020-09-09 13:23:24 -070015} unionobject;
16
17static void
18unionobject_dealloc(PyObject *self)
19{
20 unionobject *alias = (unionobject *)self;
21
Miss Islington (bot)08561342021-07-03 06:33:16 -070022 _PyObject_GC_UNTRACK(self);
23
Maggie Moss1b4552c2020-09-09 13:23:24 -070024 Py_XDECREF(alias->args);
Serhiy Storchaka2d055ce2021-07-17 22:14:57 +030025 Py_XDECREF(alias->parameters);
Neil Schemenauer0564aaf2020-10-27 11:55:52 -070026 Py_TYPE(self)->tp_free(self);
Maggie Moss1b4552c2020-09-09 13:23:24 -070027}
28
Miss Islington (bot)08561342021-07-03 06:33:16 -070029static int
30union_traverse(PyObject *self, visitproc visit, void *arg)
31{
32 unionobject *alias = (unionobject *)self;
33 Py_VISIT(alias->args);
Serhiy Storchaka2d055ce2021-07-17 22:14:57 +030034 Py_VISIT(alias->parameters);
Miss Islington (bot)08561342021-07-03 06:33:16 -070035 return 0;
36}
37
Maggie Moss1b4552c2020-09-09 13:23:24 -070038static Py_hash_t
39union_hash(PyObject *self)
40{
41 unionobject *alias = (unionobject *)self;
Miss Islington (bot)70598802021-07-16 02:02:59 -070042 PyObject *args = PyFrozenSet_New(alias->args);
43 if (args == NULL) {
44 return (Py_hash_t)-1;
Maggie Moss1b4552c2020-09-09 13:23:24 -070045 }
Miss Islington (bot)70598802021-07-16 02:02:59 -070046 Py_hash_t hash = PyObject_Hash(args);
47 Py_DECREF(args);
48 return hash;
Maggie Moss1b4552c2020-09-09 13:23:24 -070049}
50
51static int
Miss Islington (bot)03aad302021-07-17 14:10:21 -070052is_generic_alias_in_args(PyObject *args)
53{
Maggie Moss1b4552c2020-09-09 13:23:24 -070054 Py_ssize_t nargs = PyTuple_GET_SIZE(args);
55 for (Py_ssize_t iarg = 0; iarg < nargs; iarg++) {
56 PyObject *arg = PyTuple_GET_ITEM(args, iarg);
Miss Islington (bot)03aad302021-07-17 14:10:21 -070057 if (_PyGenericAlias_Check(arg)) {
Maggie Moss1b4552c2020-09-09 13:23:24 -070058 return 0;
59 }
60 }
61 return 1;
62}
63
64static PyObject *
65union_instancecheck(PyObject *self, PyObject *instance)
66{
67 unionobject *alias = (unionobject *) self;
68 Py_ssize_t nargs = PyTuple_GET_SIZE(alias->args);
69 if (!is_generic_alias_in_args(alias->args)) {
70 PyErr_SetString(PyExc_TypeError,
71 "isinstance() argument 2 cannot contain a parameterized generic");
72 return NULL;
73 }
74 for (Py_ssize_t iarg = 0; iarg < nargs; iarg++) {
75 PyObject *arg = PyTuple_GET_ITEM(alias->args, iarg);
Miss Islington (bot)b42eee72021-07-13 21:55:45 -070076 if (PyType_Check(arg)) {
77 int res = PyObject_IsInstance(instance, arg);
78 if (res < 0) {
79 return NULL;
80 }
81 if (res) {
82 Py_RETURN_TRUE;
83 }
Maggie Moss1b4552c2020-09-09 13:23:24 -070084 }
85 }
86 Py_RETURN_FALSE;
87}
88
89static PyObject *
90union_subclasscheck(PyObject *self, PyObject *instance)
91{
92 if (!PyType_Check(instance)) {
93 PyErr_SetString(PyExc_TypeError, "issubclass() arg 1 must be a class");
94 return NULL;
95 }
96 unionobject *alias = (unionobject *)self;
97 if (!is_generic_alias_in_args(alias->args)) {
98 PyErr_SetString(PyExc_TypeError,
99 "issubclass() argument 2 cannot contain a parameterized generic");
100 return NULL;
101 }
102 Py_ssize_t nargs = PyTuple_GET_SIZE(alias->args);
103 for (Py_ssize_t iarg = 0; iarg < nargs; iarg++) {
104 PyObject *arg = PyTuple_GET_ITEM(alias->args, iarg);
Miss Islington (bot)b42eee72021-07-13 21:55:45 -0700105 if (PyType_Check(arg)) {
106 int res = PyObject_IsSubclass(instance, arg);
107 if (res < 0) {
108 return NULL;
109 }
110 if (res) {
111 Py_RETURN_TRUE;
112 }
Maggie Moss1b4552c2020-09-09 13:23:24 -0700113 }
114 }
Miss Islington (bot)03aad302021-07-17 14:10:21 -0700115 Py_RETURN_FALSE;
Maggie Moss1b4552c2020-09-09 13:23:24 -0700116}
117
Maggie Moss1b4552c2020-09-09 13:23:24 -0700118static PyObject *
119union_richcompare(PyObject *a, PyObject *b, int op)
120{
Miss Islington (bot)03aad302021-07-17 14:10:21 -0700121 if (!_PyUnion_Check(b) || (op != Py_EQ && op != Py_NE)) {
122 Py_RETURN_NOTIMPLEMENTED;
Maggie Moss1b4552c2020-09-09 13:23:24 -0700123 }
124
Miss Islington (bot)03aad302021-07-17 14:10:21 -0700125 PyObject *a_set = PySet_New(((unionobject*)a)->args);
Maggie Moss1b4552c2020-09-09 13:23:24 -0700126 if (a_set == NULL) {
127 return NULL;
128 }
Miss Islington (bot)03aad302021-07-17 14:10:21 -0700129 PyObject *b_set = PySet_New(((unionobject*)b)->args);
Maggie Moss1b4552c2020-09-09 13:23:24 -0700130 if (b_set == NULL) {
Serhiy Storchakac3007ab2021-07-16 14:48:20 +0300131 Py_DECREF(a_set);
Miss Islington (bot)03aad302021-07-17 14:10:21 -0700132 return NULL;
Maggie Moss1b4552c2020-09-09 13:23:24 -0700133 }
Miss Islington (bot)03aad302021-07-17 14:10:21 -0700134 PyObject *result = PyObject_RichCompare(a_set, b_set, op);
135 Py_DECREF(b_set);
136 Py_DECREF(a_set);
Maggie Moss1b4552c2020-09-09 13:23:24 -0700137 return result;
138}
139
140static PyObject*
141flatten_args(PyObject* args)
142{
Victor Stinnerd67de0a2020-09-23 23:25:54 +0200143 Py_ssize_t arg_length = PyTuple_GET_SIZE(args);
144 Py_ssize_t total_args = 0;
Maggie Moss1b4552c2020-09-09 13:23:24 -0700145 // Get number of total args once it's flattened.
146 for (Py_ssize_t i = 0; i < arg_length; i++) {
147 PyObject *arg = PyTuple_GET_ITEM(args, i);
Miss Islington (bot)03aad302021-07-17 14:10:21 -0700148 if (_PyUnion_Check(arg)) {
Maggie Moss1b4552c2020-09-09 13:23:24 -0700149 total_args += PyTuple_GET_SIZE(((unionobject*) arg)->args);
150 } else {
151 total_args++;
152 }
153 }
154 // Create new tuple of flattened args.
155 PyObject *flattened_args = PyTuple_New(total_args);
156 if (flattened_args == NULL) {
157 return NULL;
158 }
159 Py_ssize_t pos = 0;
160 for (Py_ssize_t i = 0; i < arg_length; i++) {
161 PyObject *arg = PyTuple_GET_ITEM(args, i);
Miss Islington (bot)03aad302021-07-17 14:10:21 -0700162 if (_PyUnion_Check(arg)) {
Maggie Moss1b4552c2020-09-09 13:23:24 -0700163 PyObject* nested_args = ((unionobject*)arg)->args;
Victor Stinnerd73cf7c2020-09-26 12:48:41 +0200164 Py_ssize_t nested_arg_length = PyTuple_GET_SIZE(nested_args);
165 for (Py_ssize_t j = 0; j < nested_arg_length; j++) {
Maggie Moss1b4552c2020-09-09 13:23:24 -0700166 PyObject* nested_arg = PyTuple_GET_ITEM(nested_args, j);
167 Py_INCREF(nested_arg);
168 PyTuple_SET_ITEM(flattened_args, pos, nested_arg);
169 pos++;
170 }
171 } else {
Serhiy Storchaka6dec5252021-07-15 10:15:14 +0300172 if (arg == Py_None) {
173 arg = (PyObject *)&_PyNone_Type;
174 }
Maggie Moss1b4552c2020-09-09 13:23:24 -0700175 Py_INCREF(arg);
176 PyTuple_SET_ITEM(flattened_args, pos, arg);
177 pos++;
178 }
179 }
Miss Islington (bot)03aad302021-07-17 14:10:21 -0700180 assert(pos == total_args);
Maggie Moss1b4552c2020-09-09 13:23:24 -0700181 return flattened_args;
182}
183
184static PyObject*
185dedup_and_flatten_args(PyObject* args)
186{
187 args = flatten_args(args);
188 if (args == NULL) {
189 return NULL;
190 }
191 Py_ssize_t arg_length = PyTuple_GET_SIZE(args);
192 PyObject *new_args = PyTuple_New(arg_length);
193 if (new_args == NULL) {
Miss Islington (bot)03aad302021-07-17 14:10:21 -0700194 Py_DECREF(args);
Maggie Moss1b4552c2020-09-09 13:23:24 -0700195 return NULL;
196 }
197 // Add unique elements to an array.
Victor Stinnerd73cf7c2020-09-26 12:48:41 +0200198 Py_ssize_t added_items = 0;
Maggie Moss1b4552c2020-09-09 13:23:24 -0700199 for (Py_ssize_t i = 0; i < arg_length; i++) {
200 int is_duplicate = 0;
201 PyObject* i_element = PyTuple_GET_ITEM(args, i);
Serhiy Storchaka80844d12021-07-16 16:42:04 +0300202 for (Py_ssize_t j = 0; j < added_items; j++) {
203 PyObject* j_element = PyTuple_GET_ITEM(new_args, j);
Miss Islington (bot)03aad302021-07-17 14:10:21 -0700204 int is_ga = _PyGenericAlias_Check(i_element) &&
205 _PyGenericAlias_Check(j_element);
kj4eb41d02020-11-09 12:00:13 +0800206 // RichCompare to also deduplicate GenericAlias types (slower)
207 is_duplicate = is_ga ? PyObject_RichCompareBool(i_element, j_element, Py_EQ)
208 : i_element == j_element;
209 // Should only happen if RichCompare fails
210 if (is_duplicate < 0) {
211 Py_DECREF(args);
212 Py_DECREF(new_args);
213 return NULL;
Maggie Moss1b4552c2020-09-09 13:23:24 -0700214 }
kj4eb41d02020-11-09 12:00:13 +0800215 if (is_duplicate)
216 break;
Maggie Moss1b4552c2020-09-09 13:23:24 -0700217 }
218 if (!is_duplicate) {
219 Py_INCREF(i_element);
220 PyTuple_SET_ITEM(new_args, added_items, i_element);
221 added_items++;
222 }
223 }
224 Py_DECREF(args);
225 _PyTuple_Resize(&new_args, added_items);
226 return new_args;
227}
228
229static int
Maggie Moss1b4552c2020-09-09 13:23:24 -0700230is_unionable(PyObject *obj)
231{
Ken Jinca5a4cf2021-07-24 22:49:25 +0800232 return (obj == Py_None ||
Miss Islington (bot)03aad302021-07-17 14:10:21 -0700233 PyType_Check(obj) ||
234 _PyGenericAlias_Check(obj) ||
Ken Jinca5a4cf2021-07-24 22:49:25 +0800235 _PyUnion_Check(obj));
Maggie Moss1b4552c2020-09-09 13:23:24 -0700236}
237
kj4eb41d02020-11-09 12:00:13 +0800238PyObject *
Miss Islington (bot)03aad302021-07-17 14:10:21 -0700239_Py_union_type_or(PyObject* self, PyObject* other)
Maggie Moss1b4552c2020-09-09 13:23:24 -0700240{
Ken Jinca5a4cf2021-07-24 22:49:25 +0800241 if (!is_unionable(self) || !is_unionable(other)) {
Miss Islington (bot)85b58292021-07-18 04:59:25 -0700242 Py_RETURN_NOTIMPLEMENTED;
243 }
244
Miss Islington (bot)03aad302021-07-17 14:10:21 -0700245 PyObject *tuple = PyTuple_Pack(2, self, other);
Maggie Moss1b4552c2020-09-09 13:23:24 -0700246 if (tuple == NULL) {
247 return NULL;
248 }
Miss Islington (bot)85b58292021-07-18 04:59:25 -0700249
Miss Islington (bot)03aad302021-07-17 14:10:21 -0700250 PyObject *new_union = make_union(tuple);
Maggie Moss1b4552c2020-09-09 13:23:24 -0700251 Py_DECREF(tuple);
252 return new_union;
253}
254
255static int
256union_repr_item(_PyUnicodeWriter *writer, PyObject *p)
257{
258 _Py_IDENTIFIER(__module__);
259 _Py_IDENTIFIER(__qualname__);
260 _Py_IDENTIFIER(__origin__);
261 _Py_IDENTIFIER(__args__);
262 PyObject *qualname = NULL;
263 PyObject *module = NULL;
Serhiy Storchaka98c44332020-10-10 22:23:42 +0300264 PyObject *tmp;
Maggie Moss1b4552c2020-09-09 13:23:24 -0700265 PyObject *r = NULL;
266 int err;
267
Serhiy Storchaka6dec5252021-07-15 10:15:14 +0300268 if (p == (PyObject *)&_PyNone_Type) {
269 return _PyUnicodeWriter_WriteASCIIString(writer, "None", 4);
270 }
271
Serhiy Storchaka98c44332020-10-10 22:23:42 +0300272 if (_PyObject_LookupAttrId(p, &PyId___origin__, &tmp) < 0) {
Maggie Moss1b4552c2020-09-09 13:23:24 -0700273 goto exit;
274 }
275
Serhiy Storchaka98c44332020-10-10 22:23:42 +0300276 if (tmp) {
277 Py_DECREF(tmp);
278 if (_PyObject_LookupAttrId(p, &PyId___args__, &tmp) < 0) {
Maggie Moss1b4552c2020-09-09 13:23:24 -0700279 goto exit;
280 }
Serhiy Storchaka98c44332020-10-10 22:23:42 +0300281 if (tmp) {
Maggie Moss1b4552c2020-09-09 13:23:24 -0700282 // It looks like a GenericAlias
Serhiy Storchaka98c44332020-10-10 22:23:42 +0300283 Py_DECREF(tmp);
Maggie Moss1b4552c2020-09-09 13:23:24 -0700284 goto use_repr;
285 }
286 }
287
288 if (_PyObject_LookupAttrId(p, &PyId___qualname__, &qualname) < 0) {
289 goto exit;
290 }
291 if (qualname == NULL) {
292 goto use_repr;
293 }
294 if (_PyObject_LookupAttrId(p, &PyId___module__, &module) < 0) {
295 goto exit;
296 }
297 if (module == NULL || module == Py_None) {
298 goto use_repr;
299 }
300
301 // Looks like a class
302 if (PyUnicode_Check(module) &&
303 _PyUnicode_EqualToASCIIString(module, "builtins"))
304 {
305 // builtins don't need a module name
306 r = PyObject_Str(qualname);
307 goto exit;
308 }
309 else {
310 r = PyUnicode_FromFormat("%S.%S", module, qualname);
311 goto exit;
312 }
313
314use_repr:
315 r = PyObject_Repr(p);
316exit:
317 Py_XDECREF(qualname);
318 Py_XDECREF(module);
319 if (r == NULL) {
320 return -1;
321 }
322 err = _PyUnicodeWriter_WriteStr(writer, r);
323 Py_DECREF(r);
324 return err;
325}
326
327static PyObject *
328union_repr(PyObject *self)
329{
330 unionobject *alias = (unionobject *)self;
331 Py_ssize_t len = PyTuple_GET_SIZE(alias->args);
332
333 _PyUnicodeWriter writer;
334 _PyUnicodeWriter_Init(&writer);
335 for (Py_ssize_t i = 0; i < len; i++) {
336 if (i > 0 && _PyUnicodeWriter_WriteASCIIString(&writer, " | ", 3) < 0) {
337 goto error;
338 }
339 PyObject *p = PyTuple_GET_ITEM(alias->args, i);
340 if (union_repr_item(&writer, p) < 0) {
341 goto error;
342 }
343 }
344 return _PyUnicodeWriter_Finish(&writer);
345error:
346 _PyUnicodeWriter_Dealloc(&writer);
347 return NULL;
348}
349
350static PyMemberDef union_members[] = {
351 {"__args__", T_OBJECT, offsetof(unionobject, args), READONLY},
352 {0}
353};
354
355static PyMethodDef union_methods[] = {
356 {"__instancecheck__", union_instancecheck, METH_O},
357 {"__subclasscheck__", union_subclasscheck, METH_O},
358 {0}};
359
Serhiy Storchaka2d055ce2021-07-17 22:14:57 +0300360
361static PyObject *
362union_getitem(PyObject *self, PyObject *item)
363{
364 unionobject *alias = (unionobject *)self;
365 // Populate __parameters__ if needed.
366 if (alias->parameters == NULL) {
367 alias->parameters = _Py_make_parameters(alias->args);
368 if (alias->parameters == NULL) {
369 return NULL;
370 }
371 }
372
373 PyObject *newargs = _Py_subs_parameters(self, alias->args, alias->parameters, item);
374 if (newargs == NULL) {
375 return NULL;
376 }
377
Miss Islington (bot)21db59f2021-07-22 15:18:49 -0700378 PyObject *res;
Miss Islington (bot)85b58292021-07-18 04:59:25 -0700379 Py_ssize_t nargs = PyTuple_GET_SIZE(newargs);
Miss Islington (bot)21db59f2021-07-22 15:18:49 -0700380 if (nargs == 0) {
381 res = make_union(newargs);
382 }
383 else {
384 res = PyTuple_GET_ITEM(newargs, 0);
385 Py_INCREF(res);
386 for (Py_ssize_t iarg = 1; iarg < nargs; iarg++) {
387 PyObject *arg = PyTuple_GET_ITEM(newargs, iarg);
388 Py_SETREF(res, PyNumber_Or(res, arg));
389 if (res == NULL) {
390 break;
Miss Islington (bot)85b58292021-07-18 04:59:25 -0700391 }
Miss Islington (bot)85b58292021-07-18 04:59:25 -0700392 }
393 }
Serhiy Storchaka2d055ce2021-07-17 22:14:57 +0300394 Py_DECREF(newargs);
395 return res;
396}
397
398static PyMappingMethods union_as_mapping = {
399 .mp_subscript = union_getitem,
400};
401
402static PyObject *
403union_parameters(PyObject *self, void *Py_UNUSED(unused))
404{
405 unionobject *alias = (unionobject *)self;
406 if (alias->parameters == NULL) {
407 alias->parameters = _Py_make_parameters(alias->args);
408 if (alias->parameters == NULL) {
409 return NULL;
410 }
411 }
412 Py_INCREF(alias->parameters);
413 return alias->parameters;
414}
415
416static PyGetSetDef union_properties[] = {
Miss Islington (bot)8a37e8c2021-07-26 12:02:58 -0700417 {"__parameters__", union_parameters, (setter)NULL, "Type variables in the types.UnionType.", NULL},
Serhiy Storchaka2d055ce2021-07-17 22:14:57 +0300418 {0}
419};
420
Maggie Moss1b4552c2020-09-09 13:23:24 -0700421static PyNumberMethods union_as_number = {
kj4eb41d02020-11-09 12:00:13 +0800422 .nb_or = _Py_union_type_or, // Add __or__ function
Maggie Moss1b4552c2020-09-09 13:23:24 -0700423};
424
Miss Islington (bot)47299762021-07-30 02:31:54 -0700425static const char* const cls_attrs[] = {
426 "__module__", // Required for compatibility with typing module
427 NULL,
428};
429
430static PyObject *
431union_getattro(PyObject *self, PyObject *name)
432{
433 unionobject *alias = (unionobject *)self;
434 if (PyUnicode_Check(name)) {
435 for (const char * const *p = cls_attrs; ; p++) {
436 if (*p == NULL) {
437 break;
438 }
439 if (_PyUnicode_EqualToASCIIString(name, *p)) {
440 return PyObject_GetAttr((PyObject *) Py_TYPE(alias), name);
441 }
442 }
443 }
444 return PyObject_GenericGetAttr(self, name);
445}
446
Miss Islington (bot)03aad302021-07-17 14:10:21 -0700447PyTypeObject _PyUnion_Type = {
Maggie Moss1b4552c2020-09-09 13:23:24 -0700448 PyVarObject_HEAD_INIT(&PyType_Type, 0)
Miss Islington (bot)8a37e8c2021-07-26 12:02:58 -0700449 .tp_name = "types.UnionType",
Maggie Moss1b4552c2020-09-09 13:23:24 -0700450 .tp_doc = "Represent a PEP 604 union type\n"
451 "\n"
452 "E.g. for int | str",
453 .tp_basicsize = sizeof(unionobject),
454 .tp_dealloc = unionobject_dealloc,
455 .tp_alloc = PyType_GenericAlloc,
Miss Islington (bot)08561342021-07-03 06:33:16 -0700456 .tp_free = PyObject_GC_Del,
457 .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
458 .tp_traverse = union_traverse,
Maggie Moss1b4552c2020-09-09 13:23:24 -0700459 .tp_hash = union_hash,
Miss Islington (bot)47299762021-07-30 02:31:54 -0700460 .tp_getattro = union_getattro,
Maggie Moss1b4552c2020-09-09 13:23:24 -0700461 .tp_members = union_members,
462 .tp_methods = union_methods,
463 .tp_richcompare = union_richcompare,
Serhiy Storchaka2d055ce2021-07-17 22:14:57 +0300464 .tp_as_mapping = &union_as_mapping,
Maggie Moss1b4552c2020-09-09 13:23:24 -0700465 .tp_as_number = &union_as_number,
466 .tp_repr = union_repr,
Serhiy Storchaka2d055ce2021-07-17 22:14:57 +0300467 .tp_getset = union_properties,
Maggie Moss1b4552c2020-09-09 13:23:24 -0700468};
469
Miss Islington (bot)03aad302021-07-17 14:10:21 -0700470static PyObject *
471make_union(PyObject *args)
Maggie Moss1b4552c2020-09-09 13:23:24 -0700472{
473 assert(PyTuple_CheckExact(args));
474
Serhiy Storchakac3007ab2021-07-16 14:48:20 +0300475 args = dedup_and_flatten_args(args);
476 if (args == NULL) {
477 return NULL;
478 }
479 if (PyTuple_GET_SIZE(args) == 1) {
480 PyObject *result1 = PyTuple_GET_ITEM(args, 0);
481 Py_INCREF(result1);
482 Py_DECREF(args);
483 return result1;
484 }
485
Miss Islington (bot)85b58292021-07-18 04:59:25 -0700486 unionobject *result = PyObject_GC_New(unionobject, &_PyUnion_Type);
Maggie Moss1b4552c2020-09-09 13:23:24 -0700487 if (result == NULL) {
Serhiy Storchakac3007ab2021-07-16 14:48:20 +0300488 Py_DECREF(args);
Maggie Moss1b4552c2020-09-09 13:23:24 -0700489 return NULL;
490 }
491
Serhiy Storchaka2d055ce2021-07-17 22:14:57 +0300492 result->parameters = NULL;
Serhiy Storchakac3007ab2021-07-16 14:48:20 +0300493 result->args = args;
Miss Islington (bot)000b9e82021-07-03 13:51:10 -0700494 _PyObject_GC_TRACK(result);
Maggie Moss1b4552c2020-09-09 13:23:24 -0700495 return (PyObject*)result;
496}