It would be much more helpful to make it possible to use Python 2 syntax with a Python 3 interpreter. Ideally as an extension for Python 3. That would allow people to incrementally port.
With stuff like this, any ports of existing Python 2 codebases are wont to lead to tons of subtle bugs. No wonder Python 3 adoption is as low as it is.
I feel like it's still a better idea to migrate back to python 2.7 and update it to match python 3 features in a backwards compatible way. At the very least there needs to be a way to interop between python 2 and python 3 code without modifying the python 2 code.
I haven't used python for a while though. Maybe they found a solution to the python 2/3 problem already.
There are pieces of Python 3 that are syntax errors in Python 2. And there are Python 2-isms that are valid syntax in Python 3 but have a different interpretation. It's not as simple as importing certain features (which creates a sort of language version hybrid).
The idea to allow one project to switch between Python 2 and Python 3 for individual files is more interesting, but practically speaking would lead to sort of a mess.
It has definitely been a painful process to port from python 2 to 3. We have one developer who has been pushing hard for this, and while it may not be a defensible business position we believe it's the right thing as members of the community.
There are some nontrivial improvements in Python 3 (async) that we want, but more than that we don't want python to split and languish. We think that by taking a step into python 3 (and porting our remaining dependencies) we can make a small dent.
Your idea is good but i think it has to be taken one step further. You should be able to import ANY module, third party or not, and specify under which version to run it. What we need is interop between python 2 and 3.
Just look at this thread. Everybody who disses python 3 does it for library support, library support and library support. If you could write your own code in python 3 but still use libraries remaining on 2.7 most people would switch in a heartbeat. After that it's just a matter of time before the libraries transition to 3. Now we are stuck in a chicken and egg situation where nobody wants to make a move.
It's easy to port to python 3 but I think the holdup with some libraries is that they want to support both 2 and 3 with the same library so that devs who cannot upgrade the python on their system don't get left behind. Supporting both at the same time is possible but takes longer in most cases.
It's not quite that simple. Not all code that runs on Python 2 will be syntax-compatible with Python 3, and vice versa. You can, with some effort, use a subset of the Python syntax that is compatible with both interpreters, but many libraries do not do that, but ship separate Python 2 and Python 3 versions if they support both.
So restricting yourself to a common subset of Python 2/3 and adding compatibility helpers in your code is the preferred approach now a days?
I'm still not convinced about the whole Python 2 to 3 conversion being worth it (asides from the fact that not porting means your project is seen as not being actively maintained). It has led to added complexity in code so that it works on both versions, increased difficulty in packaging/distribution, having to test/debug on both versions, obsolescencing vast amounts of code that will never be ported, confusion among new users, untold man-hours being spent, ...
I don't mean to be sound so down on Python 3, but it has caused me nothing but additional work and frustration. The supposed benefits of Python 3 are still years away.
My last few Python projects have started out as Python 3, but ended up as 2 due to missing library support.
Would it be at all feasible to enable Python 3 to import Python 2 code? I imagine this could be done without making Python 3 fully backwards compatible, but I might be wrong.
Because you actually can write code that is compatible with both Python 2 and 3.
Also major issues people have with migration is unicode. In respect of unicode, majority of the code is simply broken and fails to work on Python 3 because Python 3 is more strict about it.
In Python 2 you store text and binary data as bytes (no distinction, there is unicode type but it's more hassle to use it and frankly almost no one does use it) while in Python 3 text and binary data are two distinct types.
So if you have code in Python 2 and you did not distinguish what is text and what is binary now you have to go through your entire code and identify all those parts, this is especially hard since Python is dynamically typed language and you don't have type checker to help you with that.
This is also why it is much easier to write Python 3 code and make it run on Python 2 as well than the other way around.
As for having interpreter compatibility layer. First python does not care about extension you use, and unlike some languages it actually allows you to install multiple versions at the same time without conflicts (checked 2.4 all the way to 3.5). You can easily control which version you want to use by shabang, for example:
reply