[in progress] python 2 and 3 compatibility without 2to3#2095
Conversation
brutally replace all `exeption <type>, <name>:` by `exception <type> as <name> :` `exception <type>, <type> :` should not be present anywhere in the code anymore, or should be present with explicit tuple as `exception (<type>, <type>)`
2to3 makes a better job than regexp
this should allow a more compatible codebase between python 2.x and 3.x
|
Thanks, I've been thinking of aiming for this. I think For unicode strings, I think the approach Django took was to use |
|
I removed the exec fix, i can push this branch onto the main repository so that everyone can have acces to it. |
|
Please do not do this. Maintaining Python3 compatible source in Python 2 is an ugly pain. |
|
I'm not sure it's necessarily much worse, given that we're only I suggest we just progress one step at a time, as we've done with the |
|
My main objection is the print function, which I really, really hate. |
|
Counterpoints to my own argument:
But I still would vastly prefer to not apply print_function everywhere. At least not yet. |
|
My own plan was to apply it first in places where we're using the |
There was a problem hiding this comment.
The extra parenthesis here (and a couple lines below) are not needed.
|
I'd definitely be in favor of this. Currently developing IPython for Python 3 is a pain as any change you make requires at least running As an aside, Python 3 is starting to reach such a critical mass of supported packages at the distribution level (i.e., in Debian Wheezy / Ubuntu Precise) that I'm now finding myself often using Python 3 as my go-to Python intepreter. |
|
That's good to hear. I know Ubuntu is also pushing to port core |
|
Aside: if only |
|
My pattern has been similar to @takluyver's - when more complicated behavior is called for, I add print_function, but not before. I think to do so across all of IPython is a huge net detriment. |
|
Shall we start by doing these things that I think are uncontroversial:
I suggest we close this PR and open a new one for those changes - this one is unwieldy, and already has a merge conflict. We could also express a preference that new modules added to the codebase should use |
|
@takluyver's suggestion seems sensible to me. code-wide print_function is a major style change, and code-wide unicode_literals will likely be a big mess (and I expect not worth it, and we should just wait for 3.3 on that one). But this PR includes several helpful little changes, which will be dwarfed by the discussion of others. |
|
ok, closing, and reopening as #2100 with @takluyver sugestion. |
|
Closing (I think you forgot to actually close it, @Carreau :) |
Logical step after #2064 where the discussion started.
Most of the fixes apply by
2to3when converting the current source tree to python 3 can be applied and are valid python 2.6 and 2.7 (not 2.5 but we don't support it), with minimal changes.The plan is here to apply theses changes as early as possible ans deactivate them when using
2to3in order to get a python2 and python3 compatible IPython code.For what I've seen right now, 2to3 is sometime a little overzealous with
print, convertingprint 'xxx',toprint('xxx', end=' ')(space) but in some place we should haveend=''(no space),and it sometime also change
print ('an'+'expression')toprint(('an'+'expression')). I detected and fixed some by hand because of failling test, but might have missed a few.The other 2 fixes I added was getting rid of
applyin some places, and convertexecstatement to a function.My guess is the harder part will be unicode strings prefix that is not valid python 3.0 to 3.2 and valid again python 3.3. One of our option might be
from __future__ import unicode_literals.It would be really cool to be able to do
python3 ipython.pyNote : This does not merge cleanly right now and is on top of #2064, we can either close #2064 then i'll rebase the all on top of master, or I'll rebase when #2064 is merged.