New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
backport python 3.0 language functionality to python 2.6 by adding 7 opcodes to ceval.c #47488
Comments
this patch touches only Python/ceval.c.
2. that, plus it defines (the new opcodes)
#define SET_ADD 17
#define STORE_LOCALS 69
#define LOAD_BUILD_CLASS 34 // 71 in py3k
#define MAKE_BYTES 35 // unused in py3k
#define POP_EXCEPT 36 // 89 in py3k
#define UNPACK_EX 94
#define BUILD_SET 109 // 104 in py3k
and some backported vars & helper functions only 2 contiguous areas of ceval.c is patched (1. & 2. - areas are this simple patch seems sufficient in theory to allow the interpreter to i wrote 2 small scripts which gives an interactive function 'compile_py3k' example demonstrating PEP-3132 extended unpacking syntax: Python 2.5.2 (r252:60911, Jun 27 2008, 21:19:51) >>> import py3to2
py3to2 server restarting with io: (4, 5)
py3to2 server: Python 3.0b1 (r30b1:64395, Jun 24 2008, 21:53:55)
py3to2 server: [GCC 3.4.6 20060404 (Red Hat 3.4.6-9)] on linux2
py3to2 server: Type "help", "copyright", "credits" or "license" for more
information.
py3to2 server:
>>> src = "a,b,*c = 1,2,3,4"
>>> codeobject = py3to2.compile_py3k(src,"","exec")
1 0 LOAD_CONST 5 ((1, 2, 3, 4))
3 UNPACK_EX_py3k 2
6 STORE_NAME 0 (a)
9 STORE_NAME 1 (b)
12 STORE_NAME 2 (c)
15 LOAD_CONST 4 (None)
18 RETURN_VALUE
>>> exec(codeobject)
>>> print a,b,c
1, 2, [3, 4]
>>> u can go c anyway, i think it would b a great boost for python 3.0 (which i think ps. i've also attempted the reverse (forward-port 2.x opcodes to 3.0), |
The first beta release for 2.6 has been made, so no new features can be |
ok |
Some remarks:
|
ideally that may be true. but its quite frustrating testing/developing new py3k software when many for example, its a difficult task to port a big project like numpy to |
I don't know why this is assigned to me. |
update: these 3k language features have been tested to work in python PEP-3104 Access to Names in Outer Scopes had to backport __build_class__ in bltinmodule.c to get metaclasses install/usage summary:
the script provides 3 functions similar to those in __builtin__: right now, working on backporting PEP-3102 & 3107 - annotations & |
import/reload now works.
also added: download: http://www-rcf.usc.edu/~kaizhu/work/py3to2/current/ patched files: there r 7 unimplemented pep's remaining: any suggested solutions? @ any rate, i think its feature complete enough to b useful in certain ################################################################################ add the magic comment '# import as py3k\n' to import / reload a script 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('PEP-3114 Renaming iterator.next() to .__next__()') print('pep3132 Extended Iterable Unpacking')
a,b,*c = numpy.random.rand(4)
print('a = %s, b = %s, c = %s'%(a,b,c)); print('#'*64)
################################################################################ |
This isn't dealing with the 2to3 conversion tool. Please do not add it. |
why not? it allows developers to migrate 2.x scripts one-by-one to py3to2 can transparently import & mix & match 2.x & 3.0 scripts (but @ the moment, every script compilable by py3to2 should b 3.0 language |
On Sun, Jul 13, 2008 at 2:03 PM, kai zhu <report@bugs.python.org> wrote:
Yes, I realize that, but there is another tool called 2to3 that |
then the 2 can complement each other well ;) i don't c any competition 2to3 -> convert 2x scripts to 3k u have to admit migrating to 3k is quite painful & slow btw, py3to2's patches minimally affects 2.x compatibility: i just ran 'make test' w/ a patched build of python 2.5.2 w/ following not bad considering it now supports 11 of the 18 (soon to b 12 & likely |
Please trust our judgment on how to use the bug tracker. This isn't a |
ported to python-2.6 & is a bit more stable (written a few py3k programs u can also test out scripts generated by 2to3 by adding to them the an example "python-2.6" script using "python-3.0" language syntax (& new features added by patch to python-2.6 (under py3k_syntax mode): sans unicode & py3k's builtins module, the above (plus __future__) py3k_syntax mode: codeobj->co_argcount now limited to range 0-0xffff with upper bits codeobj->co_kwonlyargcount (limited to range 0-0xff) is embedded in most of the trouble have been gettin kwonlyarg, annotations, & classes there is one unrelated opcode (LOAD_ATTR_py3k) added to ceval.c for my |
Recommend rejecting this. I believe that it wasn't backported for a |
hi, i'm happy i got a response on this :) anyway, can u elaborate on the "reason" y something like this was never yes, i kno the patch is rough right now (& will never get accepted in isn't that the spirit of python 2.7? in the meantime, i'm in no hurry |
This doesn't sound like it will ever be reliable. Kai Zhu, a better strategy would be for you to maintain your own |
k |
post fyi: here's moderately complex python-3.0 script (plus curry extension) i it takes a jpeg, gif... image file & outputs it in colorized ascii art. usage: |
Please don't use the bug tracker to upload unrelated code |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: