Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
gh-119127: functools.partial placeholders#119827
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
ee7333c8bcc462c67c9b4680d9009591ff5067e9388af20b3607a0b1f55801e58941453722e07a79c2af12aaa7292c767b496a9d238d9c11707b95714b38ca32bca198576493a3fd2d608529936fea348caec6e8115b8c53f5f00b202c9292c16d38400ff558ccc38fe7c82c7c9b7ef3e59d7117bfc5917957a978aaee6afe8e0ad00dd80ed352cfa9038ed549b8c71bc1fdbd30672211185510266b4fadd58a125971fbb9033650d31e5d1a3d39b09e4c5df16f12f882dd600f9cb653d255524404044e800217b38ee45011f47db3c872bdfd16189a6c6ef21c8d73ea8bd3ae70e47ed2eacf5ef78d8d30a8640e6e3d28266c305d14bf68cee642d58d6c28e8744bcbb8964704881ae6c3ad7d95e5d484File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -48,8 +48,21 @@ Placeholder is an object that can be used to signal that positional | ||
| argument place is empty when using `partial` class | ||
| */ | ||
| #define PY_CONSTANT_PLACEHOLDER 0 | ||
| static PyObject* constants[] = { | ||
| NULL, // PY_CONSTANT_PLACEHOLDER | ||
| }; | ||
| typedef struct { | ||
| PyObject_HEAD | ||
| } placeholderobject; | ||
| PyDoc_STRVAR(placeholder_doc, | ||
| "PlaceholderType()\n" | ||
| "--\n\n" | ||
| "The type of the Placeholder singleton.\n" | ||
| "Used as a placeholder for partial arguments."); | ||
| static PyObject * | ||
| placeholder_repr(PyObject *op) | ||
| @@ -74,7 +87,12 @@ placeholder_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) | ||
| PyErr_SetString(PyExc_TypeError, "PlaceholderType takes no arguments"); | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. You could use | ||
| return NULL; | ||
| } | ||
| PyObject *singleton = constants[PY_CONSTANT_PLACEHOLDER]; | ||
| if (singleton == NULL) { | ||
| singleton = PyType_GenericNew(type, NULL, NULL); | ||
| constants[PY_CONSTANT_PLACEHOLDER] = singleton; | ||
| } | ||
| return singleton; | ||
| } | ||
| static int | ||
| @@ -85,78 +103,23 @@ placeholder_bool(PyObject *v) | ||
| return -1; | ||
| } | ||
| static PyType_Slot placeholder_type_slots[] = { | ||
| {Py_tp_dealloc, placeholder_dealloc}, | ||
| {Py_tp_repr, placeholder_repr}, | ||
| {Py_tp_doc, (void *)placeholder_doc}, | ||
| {Py_tp_new, placeholder_new}, | ||
| // Number protocol | ||
| {Py_nb_bool, placeholder_bool}, | ||
| {0, 0} | ||
| }; | ||
| static PyType_Spec placeholder_type_spec = { | ||
| .name = "partial.PlaceholderType", | ||
| .basicsize = sizeof(placeholderobject), | ||
| .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE, | ||
| .slots = placeholder_type_slots | ||
| }; | ||
| typedef struct { | ||
| PyObject_HEAD | ||
| @@ -242,7 +205,7 @@ partial_new(PyTypeObject *type, PyObject *args, PyObject *kw) | ||
| return NULL; | ||
| } | ||
| pto->placeholder =PyObject_CallNoArgs((PyObject *)state->placeholder_type); | ||
dg-pb marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| Py_ssize_t nnp = 0; | ||
| Py_ssize_t nnargs = PyTuple_GET_SIZE(nargs); | ||
| PyObject *item; | ||
| @@ -1738,7 +1701,18 @@ _functools_exec(PyObject *module) | ||
| return -1; | ||
| } | ||
| // if (PyModule_AddObject(module, "Placeholder", Py_GetPlaceholder()) < 0) { | ||
| // return -1; | ||
| // } | ||
| state->placeholder_type = (PyTypeObject *)PyType_FromModuleAndSpec(module, | ||
| &placeholder_type_spec, NULL); | ||
| if (state->placeholder_type == NULL) { | ||
| return -1; | ||
| } | ||
| if (PyModule_AddType(module, state->placeholder_type) < 0) { | ||
| return -1; | ||
| } | ||
| if (PyModule_AddObject(module, "Placeholder", PyObject_CallNoArgs((PyObject *)state->placeholder_type)) < 0) { | ||
| return -1; | ||
| } | ||
| state->partial_type = (PyTypeObject *)PyType_FromModuleAndSpec(module, | ||
| @@ -1785,6 +1759,7 @@ _functools_traverse(PyObject *module, visitproc visit, void *arg) | ||
| { | ||
| _functools_state *state = get_functools_state(module); | ||
| Py_VISIT(state->kwd_mark); | ||
| Py_VISIT(state->placeholder_type); | ||
| Py_VISIT(state->partial_type); | ||
| Py_VISIT(state->keyobject_type); | ||
| Py_VISIT(state->lru_list_elem_type); | ||
| @@ -1796,6 +1771,7 @@ _functools_clear(PyObject *module) | ||
| { | ||
| _functools_state *state = get_functools_state(module); | ||
| Py_CLEAR(state->kwd_mark); | ||
| Py_CLEAR(state->placeholder_type); | ||
| Py_CLEAR(state->partial_type); | ||
| Py_CLEAR(state->keyobject_type); | ||
| Py_CLEAR(state->lru_list_elem_type); | ||