]> granicus.if.org Git - python/commitdiff
Issue #20204: Deprecation warning is now raised for builtin type without the
authorSerhiy Storchaka <storchaka@gmail.com>
Sun, 1 Mar 2015 08:03:02 +0000 (10:03 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Sun, 1 Mar 2015 08:03:02 +0000 (10:03 +0200)
__module__ attribute.

Doc/whatsnew/3.5.rst
Misc/NEWS
Objects/typeobject.c

index 2a777293964428ab43ed694bedf742a7c88be45f..8027fa38981969dae219ac463115fdfb0aff2cf1 100644 (file)
@@ -561,3 +561,8 @@ Changes in the C API
 * Removed non-documented macro :c:macro:`PyObject_REPR` which leaked references.
   Use format character ``%R`` in :c:func:`PyUnicode_FromFormat`-like functions
   to format the :func:`repr` of the object.
+
+* Because the lack of the :attr:`__module__` attribute breaks pickling and
+  introspection, a deprecation warning now is raised for builtin type without
+  the :attr:`__module__` attribute.  Would be an AttributeError in future.
+  (:issue:`20204`)
index d62e695fa2cdfa31da2e34fe856f0121ae5e9605..1c6a90ce33448bf1fe5f4ace802008b2e52ffb4e 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -88,6 +88,12 @@ Build
 - Issue #23445: pydebug builds now use "gcc -Og" where possible, to make
   the resulting executable faster.
 
+C API
+-----
+
+- Issue #20204: Deprecation warning is now raised for builtin type without the
+  __module__ attribute.
+
 Windows
 -------
 
index f0ad7fd560d6674999c81a15e5140f5fa9d0a6f5..d59108ef2c021eda89ed5c979ac82b8458ac2a6a 100644 (file)
@@ -2808,6 +2808,12 @@ PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases)
         _PyDict_SetItemId(type->tp_dict, &PyId___module__,
             PyUnicode_FromStringAndSize(
                 spec->name, (Py_ssize_t)(s - spec->name)));
+    else {
+        if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
+                "builtin type %.200s has no the __module__ attribute",
+                spec->name))
+            goto fail;
+    }
 
     return (PyObject*)res;