bpo-42128: Add __match_args__ to structseq-based classes by pablogsal · Pull Request #24732 · python/cpython
/* Fields with this name have only a field index, not a field name. They are only allowed for indices < n_visible_fields. */
// Prepare and set __match_args__ Py_ssize_t i, k; PyObject* keys = PyTuple_New(desc->n_in_sequence); if (keys == NULL) { return -1; }
for (i = k = 0; i < desc->n_in_sequence; ++i) { if (desc->fields[i].name == PyStructSequence_UnnamedField) {
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we can handle this in a better way: just exclude them from match_args. The other (much worse option IMHO) is generate some missing names for these.
if (_PyTuple_Resize(&keys, k) == -1) { goto error; }
if (PyDict_SetItemString(dict, match_args_key, keys) < 0) { goto error; }
Py_DECREF(keys); return 0;
error: Py_DECREF(keys); return -1; }
static void