Skip to content

Commit 2218ba8

Browse files
committed
add _field_defaults to PyStructSequence
Signed-off-by: Filipe Laíns <[email protected]>
1 parent 995a2d9 commit 2218ba8

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

Objects/structseq.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ static const char real_length_key[] = "n_fields";
1919
static const char unnamed_fields_key[] = "n_unnamed_fields";
2020
static const char match_args_key[] = "__match_args__";
2121
static const char named_fields_list_key[] = "_fields";
22+
static const char named_fields_defaults_key[] = "_field_defaults";
2223

2324
/* Fields with this name have only a field index, not a field name.
2425
They are only allowed for indices < n_visible_fields. */
@@ -414,7 +415,7 @@ count_members(PyStructSequence_Desc *desc, Py_ssize_t *n_unnamed_members) {
414415
static int
415416
initialize_structseq_dict(PyStructSequence_Desc *desc, PyObject* dict,
416417
Py_ssize_t n_members, Py_ssize_t n_unnamed_members) {
417-
PyObject *v;
418+
PyObject *v, *defaults;
418419

419420
#define SET_DICT_FROM_SIZE(key, value) \
420421
do { \
@@ -464,6 +465,16 @@ initialize_structseq_dict(PyStructSequence_Desc *desc, PyObject* dict,
464465
goto error;
465466
}
466467

468+
// Set _fields_defaults to an empty dir, as we don't support defaults
469+
defaults = PyDict_New();
470+
if (!defaults)
471+
goto error;
472+
473+
if (PyDict_SetItemString(dict, named_fields_defaults_key, defaults) < 0) {
474+
goto error;
475+
}
476+
477+
Py_DECREF(defaults);
467478
Py_DECREF(keys);
468479
return 0;
469480

0 commit comments

Comments
 (0)