Skip to content

Commit 490055a

Browse files
Issue #20204: Deprecation warning is now raised for builtin type without the
__module__ attribute.
1 parent 50adb9f commit 490055a

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

Doc/whatsnew/3.5.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,3 +561,8 @@ Changes in the C API
561561
* Removed non-documented macro :c:macro:`PyObject_REPR` which leaked references.
562562
Use format character ``%R`` in :c:func:`PyUnicode_FromFormat`-like functions
563563
to format the :func:`repr` of the object.
564+
565+
* Because the lack of the :attr:`__module__` attribute breaks pickling and
566+
introspection, a deprecation warning now is raised for builtin type without
567+
the :attr:`__module__` attribute. Would be an AttributeError in future.
568+
(:issue:`20204`)

Misc/NEWS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ Build
8888
- Issue #23445: pydebug builds now use "gcc -Og" where possible, to make
8989
the resulting executable faster.
9090

91+
C API
92+
-----
93+
94+
- Issue #20204: Deprecation warning is now raised for builtin type without the
95+
__module__ attribute.
96+
9197
Windows
9298
-------
9399

Objects/typeobject.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2808,6 +2808,12 @@ PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases)
28082808
_PyDict_SetItemId(type->tp_dict, &PyId___module__,
28092809
PyUnicode_FromStringAndSize(
28102810
spec->name, (Py_ssize_t)(s - spec->name)));
2811+
else {
2812+
if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
2813+
"builtin type %.200s has no the __module__ attribute",
2814+
spec->name))
2815+
goto fail;
2816+
}
28112817

28122818
return (PyObject*)res;
28132819

0 commit comments

Comments
 (0)