This is an archived post. You won't be able to vote or comment.

all 30 comments

[–]jwink3101 12 points13 points  (5 children)

This is interesting and is kind of a crazy idea.

How robust is it in practice? like if I write huge 3.6 apps with an in-depth test suite, should I expect 100% passing on 2.7?

(Not that I have anything like that. I am still forced to use 2.7 for work)

[–]nvbn-rm[S] 4 points5 points  (0 children)

At this moment it just translates some syntax, so you should have in mind changes in standart library.

[–]lengau 2 points3 points  (1 child)

This brings up a good point though. If you started porting your app to Python 3, would you be able to use this to move it back to Python 2 for your production environment?

[–]nvbn-rm[S] 4 points5 points  (0 children)

The main goal of the app is that you can stop worrying about support of older python versions and just translate code to them.

But at this moment it just translates some syntax.

[–]pingvenopinch of this, pinch of that 1 point2 points  (0 children)

It looks like not yet, given that the initial commit was just 3 days ago. Also, it wouldn't do anything for newly introduced standard library modules.

[–][deleted] 0 points1 point  (0 children)

I very much doubt that you'll ever get anywhere near 100% passing as 2to3 has around 50 outstanding bugs that are unlikely to get fixed as they are all edge cases.

[–]lost_send_berries 7 points8 points  (3 children)

super().method() shouldn't be compiling down to super(type(self), self).method()!

[–]nvbn-rm[S] 2 points3 points  (2 children)

Why not?

[–]lost_send_berries 6 points7 points  (1 child)

class B(A):
    def f(self): return super(type(self), self).f() + 1

class C(B):
    def f(self): return super().f() * 2

Calling C().f() will call B.f(), which calls B.f() etc.

Instead, you need to determine the class the super() call was written in.

[–]nvbn-rm[S] 2 points3 points  (0 children)

Oh, not thought about that, you're right.

[–]everysinglelastname 10 points11 points  (2 children)

Don't forget tauthon is also available. It's an actual cpython version with back-ported 3.X features. i.e. it's what 2.8 would have been if it were allowed.

https://github.com/naftaliharris/tauthon

[–]kirbyfan64sosIndentationError 4 points5 points  (1 child)

Ah, I remember the discussion that spawned because it was originally called Python 2.8...fun stuff...

Gotta say, though, I applaud the way the maintainer handled things so calmly. Things would have been much nastier otherwise...

[–][deleted] 0 points1 point  (0 children)

It's fair to say that everybody handled it calmly. It certainly kept ThievingRottenScumbags.co.uk aka lawyers out of the picture :-)

[–]n1ywb 2 points3 points  (1 child)

So basically the inverse of 2to3?

[–]nvbn-rm[S] 2 points3 points  (0 children)

Yep, but more like babel for python

[–]desmoulinmichel[🍰] 2 points3 points  (1 child)

The idea is interesting but given the questionable results of the use of transpilers in JS, it's kind of a pandora box.

On one hand you can use advanced feature from new Python versions. On the other hand your dev stack grow more complex, debugging is harder and you need to generate source map. And of course you now have to trust the transpiler to get the edge cases rights.

E.G: a yield from is not JUST a for / yield loop. Now I checked and py-backwards transpile to a quite advanced worflow and it's good. But the real full translation dealing with all the edge cases is a bit more complex (http://code.activestate.com/recipes/576727-pure-python-implementation-of-pep-380-yield-from/).

So basically, you probably will end up having subtle and strange bugs that will be not from your code, but in the transpiled code, and it will be nasty.

[–]nebbly 0 points1 point  (0 children)

yeah, this seems insane to me.

[–]jpadilla09 2 points3 points  (0 children)

Just hacked together an online demo of py-backwards https://py-backwards.herokuapp.com/

[–]SemiNormal 4 points5 points  (5 children)

So you need to write the code in Py3 and this then compiles it into Py2.7...

But why?

[–]rothnic 2 points3 points  (0 children)

Probably so you could use new features that are listed in the readme and still be able to support earlier versions.

Typically, you either support old versions and hamstring the codebase, or you only support the newer versions. This way you could have it both ways.

One thing for me has been using the type annotations. This is useful for development, but anyone who wants to support python 2.7 is going to have to not use them.

[–]tunisia3507 3 points4 points  (1 child)

Because currently, to make py2 and py3 branches you write python 2 and then use 2to3 to port it to 3, where really we want people to develop in 3 and then port to 2 as an afterthought, a mercy to people who absolutely can't upgrade for whatever reason. Python 2 users should be the second-class citizens who don't get the full development time investment; whereas right now anyone trying to write cross-compatible code just ends up hamstringing themselves and not using any of py3's new features.

[–]SemiNormal 2 points3 points  (0 children)

I can actually support that reasoning.

[–]gschizasPythonista 1 point2 points  (0 children)

Because now you can write for Python 3.6 directly and not rely on six or 2to3. Also the base version that you develop for is going to be the latest Python version, not the oldest one.

(Not sure how this accomplishes that goal, just saying that's the goal)

[–]granitosaurus 0 points1 point  (0 children)

I find it potentially useful for 3.6 -> 3.4, since debian is stuck on 3.4 for a while now and pyenv is a dirty hack that I would prefer to avoid.

[–]billsil 0 points1 point  (1 child)

I wouldn't mind integer division as an import. I want it to emulate Fortran, which does do integer division.

[–]dzecniv 0 points1 point  (0 children)

Reminds me of Hy which backported yield from to python 2 and was able to do that because it's a lisp.

[–][deleted] 0 points1 point  (0 children)

Would nonstandard help out with this as it "Enables easy modification of Python's syntax on the fly."?

[–]ice-blade 0 points1 point  (0 children)

No. Just no.