diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2024-09-28 17:51:49 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-28 17:51:49 (GMT) |
commit | 69a4063ca516360b5eb96f5432ad9f9dfc32a72e (patch) | |
tree | 012b043ff525c2481d7cf891fcc82c7024d9f17e /Objects/typeobject.c | |
parent | dc12237ab092f0eee7ec5882196997804e635075 (diff) | |
download | cpython-69a4063ca516360b5eb96f5432ad9f9dfc32a72e.zip cpython-69a4063ca516360b5eb96f5432ad9f9dfc32a72e.tar.gz cpython-69a4063ca516360b5eb96f5432ad9f9dfc32a72e.tar.bz2 |
gh-123339: Fix cases of inconsistency of __module__ and __firstlineno__ in classes (GH-123613)
* Setting the __module__ attribute for a class now removes the
__firstlineno__ item from the type's dict.
* The _collections_abc and _pydecimal modules now completely replace the
collections.abc and decimal modules after importing them. This
allows to get the source of classes and functions defined in these
modules.
* inspect.findsource() now checks whether the first line number for a
class is out of bound.
Diffstat (limited to 'Objects/typeobject.c')
-rw-r--r-- | Objects/typeobject.c | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 3368c1e..0e2d975 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -1435,6 +1435,9 @@ type_set_module(PyTypeObject *type, PyObject *value, void *context) PyType_Modified(type); PyObject *dict = lookup_tp_dict(type); + if (PyDict_Pop(dict, &_Py_ID(__firstlineno__), NULL) < 0) { + return -1; + } return PyDict_SetItem(dict, &_Py_ID(__module__), value); } |