[Python-Dev] Proposal for new 2to23 tool (original) (raw)
Graham Horler graham.horler at gmail.com
Mon Nov 12 01:00:27 CET 2007
- Previous message: [Python-Dev] Summary of Tracker Issues
- Next message: [Python-Dev] Proposal for new 2to23 tool
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
I have been developing in Python since 1.5, and now have to support 2.1 as a minimum version. I do like to keep my code runnable on newer versions however, and am considering the feasability of forward compatibility with Python 3.0.
I also notice the Leo[1] project could use some assistance with forward compatibility.
So I was wondering if anyone else had a need for a 2to23.py tool to help make code compatible with 3.0 but not break it for 2.x.
Such a tool could also include implementations of new builtins added in python 3.0, or work in tandem with a "py3to2" library. One such function would be "print" (which would have to be renamed to e.g. "prints" as "def print()" is a syntax error in 2.x). This would have the added benefit of staunching the flow of wasted effort into many differing implementations of such things, and maybe direct some of it into development of this tool.
Hope this is on topic, and has not already been considered and dismissed.
Thanks, Graham
[1] http://webpages.charter.net/edreamleo/front.html
P.S. a suggested prints() implementation for py3to2.py, including raising a TypeError exception for extra keyword args, and returning None.
It works in python 2.1 through to python 3.0a1.
def prints(*args, **kw): kw.setdefault('sep', ' ') kw.setdefault('end', '\n') kw.setdefault('file', sys.stdout)
if len(kw) > 3:
for k in ('sep', 'end', 'file'):
del kw[k]
if len(kw) > 1:
raise TypeError(', '.join(map(repr, kw.keys())) +
' are invalid keyword arguments for this function')
else:
raise TypeError('%r is an invalid keyword argument for this function'
% list(kw.keys())[0])
kw['file'].write(kw['sep'].join(['%s' % a for a in args]) + kw['end'])
- Previous message: [Python-Dev] Summary of Tracker Issues
- Next message: [Python-Dev] Proposal for new 2to23 tool
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]