[3.13] gh-123339: Fix cases of inconsistency of __module__ and __firstlineno__ in classes (GH-123613) (#124735)

* 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.
(cherry picked from commit 69a4063ca5)
This commit is contained in:
Serhiy Storchaka 2024-09-30 07:21:40 +03:00 committed by GitHub
parent ce0eaa6703
commit 5bf32d1300
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 110 additions and 12 deletions

View file

@ -1351,6 +1351,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);
}