PEP 469: also cover reverse migrations from 3 -> 2/3
This commit is contained in:
parent
e58c3947d5
commit
c2e9b27e6a
34
pep-0469.txt
34
pep-0469.txt
|
@ -291,6 +291,40 @@ builtin or helper function instead, in order to ensure the exact same
|
|||
semantics on both Python 2 and 3.
|
||||
|
||||
|
||||
Migrating from Python 3 to the common subset with Python 2.7
|
||||
============================================================
|
||||
|
||||
While the majority of migrations are currently from Python 2 either directly
|
||||
to Python 3 or to the common subset of Python 2 and Python 3, there are also
|
||||
some migrations of newer projects that start in Python 3 and then later
|
||||
add Python 2 support, either due to user demand, or to gain access to
|
||||
Python 2 libraries that are not yet available in Python 3 (and porting them
|
||||
to Python 3 or creating a Python 3 compatible replacement is not a trivial
|
||||
exercise).
|
||||
|
||||
In these cases, Python 2.7 compatibility is often sufficient, and the 2.7+
|
||||
only view based helper functions provided by ``future.utils`` allow the bare
|
||||
accesses to the Python 3 mapping view methods to be replaced with code that
|
||||
is compatible with both Python 2.7 and Python 3 (note, this is the only
|
||||
migration chart in the PEP that has Python 3 code on the left of the
|
||||
conversion):
|
||||
|
||||
* ``d.keys()`` -> ``viewkeys(d)``
|
||||
* ``d.values()`` -> ``viewvalues(d)``
|
||||
* ``d.items()`` -> ``viewitems(d)``
|
||||
* ``list(d.keys())`` -> ``list(d)``
|
||||
* ``list(d.values())`` -> ``listvalues(d)``
|
||||
* ``list(d.items())`` -> ``listitems(d)``
|
||||
* ``iter(d.keys())`` -> ``iter(d)``
|
||||
* ``iter(d.values())`` -> ``itervalues(d)``
|
||||
* ``iter(d.items())`` -> ``iteritems(d)``
|
||||
|
||||
As with migrations from Python 2 to the common subset, note that the hybrid
|
||||
code ends up never invoking the mapping methods directly - it only calls
|
||||
builtins and helper methods, with the latter addressing the semantic
|
||||
differences between Python 2 and Python 3.
|
||||
|
||||
|
||||
Possible changes to Python 3.5+
|
||||
===============================
|
||||
|
||||
|
|
Loading…
Reference in New Issue