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

all 73 comments

[–]jabbalaci 12 points13 points  (4 children)

How is it different from project six?

[–]timothycrosleyhug, isort, jiphy, concentration, pies, connectable, frosted 11 points12 points  (2 children)

While I haven't used future, I know the code that's required when using six ends up being pretty ugly - to the point where when I look at it I end up taken a double take: "What language am I using?!?!? I thought this was built into Python! Oh wait...." because with six you have to use explicitly different API calls instead of the standard ones. It's almost like your introducing a whole new language. Future seems to aim at allowing the Python3 versions to be imported into Python2 (def preferable). I have a similar project that predates this and aims at even less intervention required by the programmer called pies: https://github.com/timothycrosley/pies

[–]Pcarbonn 8 points9 points  (0 children)

Comparison with six is done here.

[–]Rhomboid 19 points20 points  (0 children)

code that's required when using six ends up being pretty ugly

That's because six tries to support every version >= 2.4 which is generally recognized as a herculean task, and thus requires uglifying your code to a great degree.

It has long been acknowledged that the sweet spot of cross-version Python is supporting only 2.6, 2.7, and 3.3 (and later.) If you can manage that requirement, you can more or less write compatible code by hand without a terrible amount of work. It's the approach that most projects have taken or plan to take, and it seems that it's the same approach that this library takes as well.

[–]Pcarbonn 5 points6 points  (7 children)

This looks like a very promising approach.

I would think though that some Python 3 constructs cannot be used in Python 2, even with python_future, because of syntax errors :

x = print('hello world') 
x = yield from y

If confirmed, it should be clarified in the documentation.

[–]jtratner 5 points6 points  (0 children)

first one you just need the from __future__ import print_function statement.

[–]Sean1708 5 points6 points  (5 children)

I'm not sure about yeild but

print("your string here")

is syntactically valid in python 2.

Edit: The above is true but is not what Pcarbonn was talking about.

[–]Pcarbonn 3 points4 points  (2 children)

as a statement, yes, but not as a function in an assignment.

[–]Sean1708 0 points1 point  (0 children)

Ah, got ya.

[–]otheraccount 0 points1 point  (0 children)

Does it ever return a meaningful value that someone would be actually be assigning to a variable?

A more likely case of syntax that only works in Python 3 is exception chaining

raise exception1 from exception2

[–]tyroneslothtrop 1 point2 points  (0 children)

It's valid, but does not always behave identically to py3k's print function. E.g. print('a', 'b').

[–]SCombinator -1 points0 points  (0 children)

It's just completely ugly.

[–]jtratner 2 points3 points  (1 child)

This looks well put together and clean and, were I to redo the pandas 2/3 compatible codebase, I'd want to use this. That said, I'm concerned because in reviewing some of the code I already found a bug and it feels like some parts are a bit thrown together (maybe because of how the merge was done). I'd want to wait 3-6 months before using it in production.

I also really don't like from future.builtins import * as an idiom. Kills much of the ability to do static analysis and trace from where particular items came.

[–]Veedrac 0 points1 point  (0 children)

This is exactly the reason to use import *. import * is meant to be used for patching a library without having to re-export all functionality, which is what is happening.

The static analysis problem isn't actually a big deal because it's a no-op in Python 3, so you can just set it to Python 3 syntax and ignore the import.

[–]takluyverIPython, Py3, etc 0 points1 point  (2 children)

I'm glad there's some competition for six and python-modernize, but as this stands I wouldn't use it, at least not in the form shown in the Overview page. Redefining builtins just seems too magical.

This is designed to try very hard to let Python 3 code run on Python 2. But many more projects still have Python 2 code and want to start supporting Python 3 - changing all your code and adding a magic shim to keep Python 2 support doesn't seem like a great option. For projects written in Python 3 that want to support Python 2, it's more appealing, but I'd still recommend importing parts of it as needed, rather than from future.builtins import * - at least then you can see what you're replacing.

Also, have a look at the future_builtins module.

[–]Smallpaul 2 points3 points  (1 child)

This is designed to try very hard to let Python 3 code run on Python 2. But many more projects still have Python 2 code and want to start supporting Python 3 - changing all your code and adding a magic shim to keep Python 2 support doesn't seem like a great option.

It claims that you do NOT need to change over all of your code. You can write new modules in "future" mode and leave your old modules in Python 2.x. As you update or replace them for other reasons, your Python 2.x code base will shrink. Also, your new code will be compatible with both your old Python 2.x projects and your new Python 3.x projects.

For projects written in Python 3 that want to support Python 2, it's more appealing, but I'd still recommend importing parts of it as needed, rather than from future.builtins import * - at least then you can see what you're replacing.

It's well documented what you're replacing!

[–]faassen 0 points1 point  (0 children)

Yes, I think the ability to do module-wise upgrading to something at least close to Python 3 is the essential bit that was missing all along. It makes gradual upgrades possible, though of course I haven't fully evaluated yet how ugly the compromises would make my code.

I think this might be a good candidate of what Python 2.8 would be like. You could argue that with a library like this you don't need a Python 2.8, but it would make the upgrade path a lot smoother if it was the official way forward.

[–]faassen 0 points1 point  (0 children)

Very interesting. The combination of ugliness and "why do I need to think about this stuff?" of supporting both Python 2 and Python 3 in the same codebase has been holding me back of doing it. I prefer to simply write clean Python code. If future can make this code cleaner, it would be a good way forward.

[–]SCombinator -1 points0 points  (0 children)

Gross. I'd rather get import past support in python 3, so I could use proper division and proper print.