[Python-checkins] peps: PEP 469: also cover reverse migrations from 3 -> 2/3

nick.coghlan python-checkins at python.org
Tue Apr 22 03:04:59 CEST 2014


http://hg.python.org/peps/rev/da9254eba5dd
changeset:   5467:da9254eba5dd
user:        Nick Coghlan <ncoghlan at gmail.com>
date:        Mon Apr 21 21:04:52 2014 -0400
summary:
  PEP 469: also cover reverse migrations from 3 -> 2/3

files:
  pep-0469.txt |  34 ++++++++++++++++++++++++++++++++++
  1 files changed, 34 insertions(+), 0 deletions(-)


diff --git a/pep-0469.txt b/pep-0469.txt
--- a/pep-0469.txt
+++ b/pep-0469.txt
@@ -291,6 +291,40 @@
 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+
 ===============================
 

-- 
Repository URL: http://hg.python.org/peps


More information about the Python-checkins mailing list