[issue3238] backport python 3.0 language functionality to python 2.6 by adding 7 opcodes to ceval.c
kai zhu
report at bugs.python.org
Sun Jul 13 18:08:55 CEST 2008
kai zhu <davidbranniganz at gmail.com> added the comment:
import/reload now works.
accomplished by adding 5 lines in parse_source_module (import.c) to 1st
check for the hook __builtins__.parse_source_module_py3k.
the hook will automatically compile in py3k format if it finds the magic
comment: "# import as py3k\n"
* below is a working python 3.0 script integrated w/ numpy.
also added:
pep3102 Keyword-Only Arguments
pep3112 Bytes literals in Python 3000
download: http://www-rcf.usc.edu/~kaizhu/work/py3to2/current/
patched files:
ceval.c (unchanged from last)
bltinmodule.c (unchanged from last)
import.c (added 5 continuous lines to parse_source_module)
there r 7 unimplemented pep's remaining: any suggested solutions?
pep3107 Function Annotations (easy, just haven't gotten around yet)
pep3109/3110 Exceptions in Python 3000 (hard?)
pep3120 Using UTF-8 as the default source encoding
pep3123 Making PyObject_HEAD conform to C (hard/who cares for 2.x?)
pep3131 Supporting Non-ASCII Identifiers (looks emulable)
pep3138 String representation in Python 3000
@ any rate, i think its feature complete enough to b useful in certain
areas (for me its scientific computing).
################################################################################
"""
numpy_py3k.py
this is a py3to2 demo showing a python3.0 script being run under python
2.5 &
utilizing numpy, a python2.5 extension module.
add the magic comment '# import as py3k\n' to import / reload a script
in py3k format
interactive usage:
>>> import py3to2
>>> import numpy_py3k
>>> reload(numpy_py3k)
commandline usage: python -c 'import py3to2; import numpy_py3k'
"""
# import as py3k
import numpy
print('pep3102 Keyword-Only Arguments')
# nth order polynomial fit of multiple y data
def polyfits(nth, x, *ys, rcond = None, full = False):
return [numpy.polyfit(x, y, nth, rcond, full) for y in ys]
fits = polyfits(2, # 2nd order fit
numpy.arange(16), # x data
numpy.random.rand(16), numpy.random.rand(16), # multiple
y data
rcond = numpy.MachAr().eps, # precision
full = False, # return only coeffs
)
print('fits', fits); print('#'*64)
print('pep3112 Bytes literals in Python 3000')
x = bytes( numpy.arange(256, dtype = numpy.int8).tostring() )
print('bytes', x); print('#'*64)
print('pep3114 Renaming iterator.next() to .__next__()')
x = (x for x in numpy.arange(16))
print('x.__next__()', x.__next__(), x.__next__(), x.__next__());
print('#'*64)
print('pep3132 Extended Iterable Unpacking')
a,b,*c = numpy.random.rand(4)
print('a = %s, b = %s, c = %s'%(a,b,c)); print('#'*64)
################################################################################
----------
assignee: -> collinwinter
components: +2to3 (2.x to 3.0 conversion tool), Demos and Tools, Interpreter Core, Tests -None
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue3238>
_______________________________________
More information about the Python-bugs-list
mailing list