@@ -376,6 +376,30 @@ New, Improved, and Deprecated Modules
376376
377377 (Contributed by Derek Morr; :issue: `1655 ` and :issue: `1664 `.)
378378
379+ * The :mod: `pickle ` module has been adapted for better interoperability with
380+ Python 2.x when used with protocol 2 or lower. The reorganization of the
381+ standard library changed the formal reference for many objects. For
382+ example, ``__builtin__.set `` in Python 2 is called ``builtins.set `` in Python
383+ 3. This change cofounded efforts to share data between different versions of
384+ Python. But now when protocol 2 or lower is selected, the pickler will
385+ automatically use the old Python 2 names for both loading and dumping. This
386+ remapping is turned-on by default but can be disabled with the *fix_imports *
387+ option::
388+
389+ >>> s = {1, 2, 3}
390+ >>> pickle.dumps(s, protocol=0)
391+ b'c__builtin__\nset\np0\n((lp1\nL1L\naL2L\naL3L\natp2\nRp3\n.'
392+ >>> pickle.dumps(s, protocol=0, fix_imports=False)
393+ b'cbuiltins\nset\np0\n((lp1\nL1L\naL2L\naL3L\natp2\nRp3\n.'
394+
395+ An unfortunate but unavoidable side-effect of this change is that protocol 2
396+ pickles produced by Python 3.1 won't be readable with Python 3.0. The latest
397+ pickle protocol, protocol 3, should be used when migrating data between
398+ Python 3.x implementations, as it doesn't attempt to remain compatible with
399+ Python 2.x.
400+
401+ (Contributed by Alexandre Vassalotti and Antoine Pitrou, :issue: `6137 `.)
402+
379403* A new module, :mod: `importlib ` was added. It provides a complete, portable,
380404 pure Python reference implementation of the :keyword: `import ` statement and its
381405 counterpart, the :func: `__import__ ` function. It represents a substantial
@@ -384,24 +408,6 @@ New, Improved, and Deprecated Modules
384408
385409 (Contributed by Brett Cannon.)
386410
387- * :mod: `pickle ` is now more compatible with Python 2.x when using a
388- 2.x-compatible protocol (that is, protocol 2 or lower), through translation
389- of some standard library module names to or from their Python 2.x
390- equivalents.
391-
392- This means that more (protocol 2 or lower) pickles produced by Python 3.1
393- will be reusable by Python 2.x, and vice-versa. Standard set objects are
394- an example of this improvement.
395-
396- This has the (unfortunate but unavoidable) side effect that some
397- protocol 2 pickles produced by Python 3.1 won't be readable with
398- Python 3.0. The latest pickle protocol, protocol 3, should be used when
399- migrating data between Python 3.x implementations, as it doesn't attempt
400- to remain compatible with Python 2.x.
401-
402- (Contributed by Alexandre Vassalotti and Antoine Pitrou, :issue: `6137 `.)
403-
404-
405411Optimizations
406412=============
407413
0 commit comments