|
Original |
Translation |
|
2861
|
The :mod:`pickle` module has been adapted for better interoperability with Python 2.x when used with protocol 2 or lower. The reorganization of the standard library changed the formal reference for many objects. For example, ``__builtin__.set`` in Python 2 is called ``builtins.set`` in Python 3. This change confounded efforts to share data between different versions of Python. But now when protocol 2 or lower is selected, the pickler will automatically use the old Python 2 names for both loading and dumping. This remapping is turned-on by default but can be disabled with the *fix_imports* option::
|
|
|
2862
|
>>> s = {1, 2, 3} >>> pickle.dumps(s, protocol=0) b'c__builtin__\nset\np0\n((lp1\nL1L\naL2L\naL3L\natp2\nRp3\n.' >>> pickle.dumps(s, protocol=0, fix_imports=False) b'cbuiltins\nset\np0\n((lp1\nL1L\naL2L\naL3L\natp2\nRp3\n.'
|
|
|
2863
|
An unfortunate but unavoidable side-effect of this change is that protocol 2 pickles produced by Python 3.1 won't be readable with Python 3.0. The latest pickle protocol, protocol 3, should be used when migrating data between Python 3.x implementations, as it doesn't attempt to remain compatible with Python 2.x.
|
|
|
2864
|
(Contributed by Alexandre Vassalotti and Antoine Pitrou, :issue:`6137`.)
|
|
|
2865
|
A new module, :mod:`importlib` was added. It provides a complete, portable, pure Python reference implementation of the :keyword:`import` statement and its counterpart, the :func:`__import__` function. It represents a substantial step forward in documenting and defining the actions that take place during imports.
|
|
|
2866
|
|
2867
|
The new I/O library (as defined in :pep:`3116`) was mostly written in Python and quickly proved to be a problematic bottleneck in Python 3.0. In Python 3.1, the I/O library has been entirely rewritten in C and is 2 to 20 times faster depending on the task at hand. The pure Python version is still available for experimentation purposes through the ``_pyio`` module.
|
|
|
2868
|
(Contributed by Amaury Forgeot d'Arc and Antoine Pitrou.)
|
|
|
2869
|
Added a heuristic so that tuples and dicts containing only untrackable objects are not tracked by the garbage collector. This can reduce the size of collections and therefore the garbage collection overhead on long-running programs, depending on their particular use of datatypes.
|
|
|
2870
|
(Contributed by Antoine Pitrou, :issue:`4688`.)
|
|