cpython: e4c065b2db49 (original) (raw)
Mercurial > cpython
changeset 82235:e4c065b2db49
Issue #15022: Ensure all pickle protocols are supported. [#15022]
Eric Snow ericsnowcurrently@gmail.com | |
---|---|
date | Sat, 16 Feb 2013 18:20:32 -0700 |
parents | 05e8d82b19a6 |
children | 65eaac000147 |
files | Lib/test/test_types.py Objects/namespaceobject.c |
diffstat | 2 files changed, 32 insertions(+), 4 deletions(-)[+] [-] Lib/test/test_types.py 11 Objects/namespaceobject.c 25 |
line wrap: on
line diff
--- a/Lib/test/test_types.py +++ b/Lib/test/test_types.py @@ -1159,10 +1159,15 @@ class SimpleNamespaceTests(unittest.Test def test_pickle(self): ns = types.SimpleNamespace(breakfast="spam", lunch="spam")
ns_pickled = pickle.dumps(ns)[](#l1.7)
ns_roundtrip = pickle.loads(ns_pickled)[](#l1.8)
for protocol in range(pickle.HIGHEST_PROTOCOL + 1):[](#l1.9)
pname = "protocol {}".format(protocol)[](#l1.10)
try:[](#l1.11)
ns_pickled = pickle.dumps(ns, protocol)[](#l1.12)
except TypeError as e:[](#l1.13)
raise TypeError(pname) from e[](#l1.14)
ns_roundtrip = pickle.loads(ns_pickled)[](#l1.15)
self.assertEqual(ns, ns_roundtrip)[](#l1.17)
self.assertEqual(ns, ns_roundtrip, pname)[](#l1.18)
--- a/Objects/namespaceobject.c +++ b/Objects/namespaceobject.c @@ -173,6 +173,29 @@ namespace_richcompare(PyObject *self, Py } +PyDoc_STRVAR(namespace_reduce__doc__, "Return state information for pickling"); + +static PyObject * +namespace_reduce(register _PyNamespaceObject *ns) +{
- result = PyTuple_Pack(3, (PyObject *)Py_TYPE(ns), args, ns->ns_dict);
- Py_DECREF(args);
- return result;
+} + + +static PyMethodDef namespace_methods[] = {
- {"reduce", (PyCFunction)namespace_reduce, METH_NOARGS,
namespace_reduce__doc__},[](#l2.25)
- {NULL, NULL} /* sentinel */
+}; + + PyDoc_STRVAR(namespace_doc, "A simple attribute-based namespace.\n[](#l2.31) \n[](#l2.32) @@ -207,7 +230,7 @@ PyTypeObject _PyNamespace_Type = { 0, /* tp_weaklistoffset / 0, / tp_iter / 0, / tp_iternext */