* Strings (:class:`str`) and :class:`bytes`.
:term:`Bytes-like objects <bytes-like object>` like :class:`bytearray` are
marshalled as :class:`!bytes`.
-* Containers: :class:`tuple`, :class:`list`, :class:`set`, :class:`frozenset`,
- and (since :data:`version` 5), :class:`slice`.
+* Containers: :class:`tuple`, :class:`list`, :class:`dict`, :class:`frozendict`
+ (since :data:`version` 6), :class:`set`, :class:`frozenset`, and
+ :class:`slice` (since :data:`version` 5).
It should be understood that these are supported only if the values contained
therein are themselves supported.
Recursive containers are supported since :data:`version` 3.
Added format version 5, which allows marshalling slices.
+.. versionchanged:: next
+
+ Added format version 6, which allows marshalling :class:`frozendict`.
+
The module defines these functions:
4 Python 3.4 Efficient representation of short strings
------- --------------- ----------------------------------------------------
5 Python 3.14 Support for :class:`slice` objects
+ ------- --------------- ----------------------------------------------------
+ 6 Python 3.15 Support for :class:`frozendict` objects
======= =============== ====================================================
Py_ssize_t);
PyAPI_FUNC(PyObject *) PyMarshal_WriteObjectToString(PyObject *, int);
-#define Py_MARSHAL_VERSION 5
+#define Py_MARSHAL_VERSION 6
PyAPI_FUNC(long) PyMarshal_ReadLongFromFile(FILE *);
PyAPI_FUNC(int) PyMarshal_ReadShortFromFile(FILE *);
self.helper(dictobj)
self.helper3(dictobj)
+ def testFrozenDict(self):
+ for obj in self.keys:
+ dictobj = frozendict({"hello": obj, "goodbye": obj, obj: "hello"})
+ self.helper(dictobj)
+
+ for version in range(6):
+ with self.assertRaises(ValueError):
+ marshal.dumps(dictobj, version)
+
def testModule(self):
with open(__file__, "rb") as f:
code = f.read()
with self.subTest(obj=str(obj)):
self.helper(obj)
- for version in range(4):
+ for version in range(5):
with self.assertRaises(ValueError):
marshal.dumps(obj, version)
Py_ssize_t pos;
PyObject *key, *value;
if (PyFrozenDict_CheckExact(v)) {
+ if (p->version < 6) {
+ w_byte(TYPE_UNKNOWN, p);
+ p->error = WFERR_UNMARSHALLABLE;
+ return;
+ }
+
W_TYPE(TYPE_FROZENDICT, p);
}
else {