gh-126072: do not add None to co_consts if there is no docstring (GH-126101)

This commit is contained in:
Xuanteng Huang 2024-10-30 17:01:09 +08:00 committed by GitHub
parent 2ab377a47c
commit 35df4eb959
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 148 additions and 58 deletions

View file

@ -162,7 +162,8 @@ PyFunction_NewWithQualName(PyObject *code, PyObject *globals, PyObject *qualname
PyObject *consts = code_obj->co_consts;
assert(PyTuple_Check(consts));
PyObject *doc;
if (PyTuple_Size(consts) >= 1) {
if (code_obj->co_flags & CO_HAS_DOCSTRING) {
assert(PyTuple_Size(consts) >= 1);
doc = PyTuple_GetItem(consts, 0);
if (!PyUnicode_Check(doc)) {
doc = Py_None;