MOE
MOE copied to clipboard
Make MOE Python 3.4-compatible
Python 2.7 is pretty much at the end of it's support life-span (and way past the end of development). We dev'd for 2.7 originally b/c of external constraints in our first runtime environments. Those are now gone.
The python-suggested basic workflow for doing this conversion: https://docs.python.org/3/whatsnew/3.0.html#porting-to-python-3-0 more detailed: https://docs.python.org/3/howto/pyporting.html
This ticket is for tracking what needs to get changed. This is not a complete list but hopefully covers the big ones. Hopefully the "-3" option from the prev link covers these:
- Paste library not supported in Python 3.x: I believe we use paste (paster?) as part of pyramid. They have a workaround: http://docs.pylonsproject.org/projects/pyramid/en/1.3-branch/whatsnew-1.3.html Note that pyramid itself is compatible with 3.4.
- language changes that i know are relevant to us:
-
print
is now a statement (wow thank god) - integer division returns a float. Use
a // b
to get the old C-style, truncating division. - xrange is gone, range now does what xrange used to do. to get old range behavior, coerce xrange output to a list.
- dict.iterkeys, iteritems, etc. are gone. dict.key, etc. now return "itemview" which is more similar to an iterator.
- zip returns an iterator (instead of a list)
- new metaclass syntax
- total redefine of how unicode vs binary/byte data is handled; i don't think this applies to us. ** https://docs.python.org/2/library/2to3.html hopefully fixes many (all?) of these issues automagically
-
something cool:
-
function annotations: http://legacy.python.org/dev/peps/pep-3107/ We annotate params/types separately in the docstring. This lets you do it in the arglist:
f(a : "a thing", b : "another thing", c : "whoa", ): pass
which is all accessible introspectively.
-
exception chaining: https://docs.python.org/3/whatsnew/3.0.html#changes-to-exceptions if handlers run into issues, you can throw new exceptions and have the old ones saved. could be nice for holding onto errors from C++ where we attempt handling/fixing in Python or try to reinvoke C++ or whatnot.