The real problem with Python 3 - no business case for conversion(was "I strongly dislike Python 3")

D

David Cournapeau

How about a basic how-to document?  I maintain PyGreSQL and would like
to move it to 3.x right now but I don't even know what the issues are.

One thing that would be very useful is how to maintain something that
works on 2.x and 3.x, but not limiting yourself to 2.6. Giving up
versions below 2.6 is out of the question for most projects with a
significant userbase IMHO. As such, the idea of running the python 3
warnings is not so useful IMHO - unless it could be made to work
better for python 2.x < 2.6, but I am not sure the idea even makes
sense.
Or is there no change at the C level?  That would make things easy.

There are quite a few, but outside of the big pain point of
strings/byte/unicode which is present at python level as well, a lot
of the issues are not so big (and even simpler to deal with). For
example, although numpy took time to port (and is still experimental
in nature), it took me a couple of hours to get a basic scipy working
(numpy uses a lot of C api dark corners, whereas scipy is much more
straightforward in its usage of the C API).

David
 
S

Stefan Behnel

Steven D'Aprano, 05.07.2010 08:31:
That's pure FUD.

Python 2.7 will be supported longer than the normal support period for
versions 2.6, 2.5, 2.4, ... so if you have a new project that requires
libraries that aren't available for 3.1, then go right ahead and use 2.7.
By the time 2.7 is no longer supported (probably around the time 3.4
comes out?), the library situation will be fixed.

Those 3.1 features that can be backported to 2.x have been, specifically
to reduce the pain in porting 2.7-based applications to 3.x. Feature-
wise, 2.7 is designed to ease the transition from the 2.x series to the
3.x series. Claiming that it's not advisable to use 2.7 is simply
nonsense.

Not to forget about the 2to3 tool. If you write code for 2.6 or 2.7 now,
you can actually port it automatically and continuously, and do the final
switch when you think it's time. So both choices (2 or 3) are real and
available.

Stefan
 
D

D'Arcy J.M. Cain

One thing that would be very useful is how to maintain something that
works on 2.x and 3.x, but not limiting yourself to 2.6. Giving up
versions below 2.6 is out of the question for most projects with a

Yes, PyGreSQL officially supports 2.3 and up. That means that we can't
use "from __future__". We might be able to bump that to 2.4 in the
next release but I wouldn't want to jump all the way to 2.6 in one
version release.
 
S

Steven

    The Twisted team has a list of what they need:

"http://stackoverflow.com/questions/172306/how-are-you-planning-on-han..."

Here's what I got from a quick google review of the below four
projects and python 3.
     * Zope Interface
Here's a blog from a core contributer to Zope, Lennart Regebro
claiming Zope Interface now works with Python 3:
http://regebro.wordpress.com/2010/04/29/zope-interface-3-6-0-released-with-python-3-support/
I have no idea if this is official Zope, but it does indicate strong
progress.
     * PyCrypto
Couldn't find much. Found this from an email on Pycrypto mailing
list:
http://lists.dlitz.net/pipermail/pycrypto/2010q2/000244.html
"""
Hi Tobias
> Does Pycrypto work with Python 3.x now?

To my knowledge PyCrypto doesn't work yet with Python 3.x.
Around 30% of the test cases are still fail. If you want me
to check which of the components are pass, please let me know.

Cheers,
Christoph"""
So someone has been looking at Python 3, but doesn't look like much is
being done.
     * PyOpenSSL
Couldn't find anything.
     * PyGTK
This one shows real progress. There is a bug filed for Python 3
support:
https://bugzilla.gnome.org/show_bug.cgi?id=566641
Key comment on that bug:
"""John Ehresman [developer] 2010-04-17 16:02:43 UTC

I just pushed to the py3k branch a couple of fixes to bugs that are
independent
of the changes for python3 so all tests pass under both python 2.5 and
python3.1. It's probably time to think about landing this on the
master
branch; obviously we want to avoid regressions in python2 support.
What needs
to be done before this lands on master?"""
A couple of comments follow about when to merge Python 3 support. So
it looks like they are almost there.

Conclusion: 2 of 4 dependencies that Twisted needs to port to Python
3 show strong progress towards completing the port.

Steven Rumbalski
 
G

Giampaolo Rodolà

2010/7/6 David Cournapeau said:
There are quite a few, but outside of the big pain point of
strings/byte/unicode which is present at python level as well, a lot
of the issues are not so big (and even simpler to deal with). For
example, although numpy took time to port (and is still experimental
in nature), it took me a couple of hours to get a basic scipy working
(numpy uses a lot of C api dark corners, whereas scipy is much more
straightforward in its usage of the C API).

David


As for this aspect, I made a port as such (C extension) for psutil,
and it hasn't been too difficult, I must admit.

For those interested here is a detailed explanation of all the steps I
faced, along with revision changes:
http://code.google.com/p/psutil/iss...sys Status Milestone Opened Owner Progress#c9


--- Giampaolo
http://code.google.com/p/pyftpdlib
http://code.google.com/p/psutil/
 
R

rantingrick

In his post on this thread, Martin Loewis volunteered to list what he
knows from psycopg2 if someone else will edit.

Now we are getting somewhere! This is the community spirit i want to
see. You don't have to give much people, every little bit counts. But
for Google's sake we need to work together to get this thing done.
Let's get a list together of 3rd party modules that are "must haves"
and start knocking on doors, evangelizing, air dropping leaflets,
spreading the word, whatever it takes! The revolution is not going to
happen whilst we sleep -- not the Python revolution that is!

Get the lead out c.l.p!
 
L

Luis M. González

    That's the real issue, not parentheses on the "print" statement.
Where's the business case for moving to Python 3?   It's not faster.
It doesn't do anything you can't do in Python 2.6.  There's no
"killer app" for it. End of life for Python 2.x is many years away;
most server Linux distros aren't even shipping with 2.6 yet. How can a
business justify spending money on conversion to Python 3?

    If Python 3 came with Unladen Swallow, and ran several times
faster than Python 2.x, there'd be a strong business case for
conversion.  Especially for large sites with racks of servers
grinding through slow CPython code.  But it looks like Unladen
Swallow will be available for 2.6 before it's available for 3.x.
So that's not a selling point for 3.x.

    Python 3 is a nice cleanup of some legacy syntax issues.  But
that's just not enough.  Perl 6 is a nice cleanup of Perl 5, and
look how that went.  Ten years on, it's not even mainstream, let
alone dominant.

    This has all been said before. See "Python 3.0: What s The Point?"
from December 2008:

http://jens.mooseyard.com/2008/12/python-30-whats-the-point/

    Not much has changed since then.

    What I'm not seeing is a deployment plan along these lines:

    1.  Identify key modules which must be converted before Python 3
        can be used in production environments.

    2.  Get those modules converted to Python 3.

    3.  Put together a distribution for the major platforms (at least
        Linux and Windows) with builds of those modules.  This
        could be done on PyPi, which is at present is mostly a link
        farm, not a repository.

    4.  Get some major distros, like Debian and ActiveState, to
        include Python 3, as "python3", not as the primary Python,
        so there are no conflicts.  (Debian already has a formal
        policy to keep Python versions separate.)

    5.  Get at least two major hosting services to put up Python 3.

    6.  Get at least two popular end-user programs (not modules) to
        support Python 3.

    7.  Publicize some success stories.

Unless the Python 3 enthusiasts get their act together and work much
harder on providing an easy transition experience, it's not going to
happen.

                                John Nagle

What's the problem?
Python 2.xx will he around for a long time. It will be supported and
you can use it for your existing projects for as long a you want.
On the other hand, if you have a new project and you plan to make it
successful and usable for many years to come, you should seriously
consider using Python 3.
 
P

Paul McGuire

One thing that would be very useful is how to maintain something that
works on 2.x and 3.x, but not limiting yourself to 2.6. Giving up
versions below 2.6 is out of the question for most projects with a
significant userbase IMHO. As such, the idea of running the python 3
warnings is not so useful IMHO - unless it could be made to work
better for python 2.x < 2.6, but I am not sure the idea even makes
sense.
This is exactly how I felt about my support for pyparsing, that I was
trying continue to provide support for 2.3 users, up through 3.x
users, with a single code base. (This would actually have been
possible if I had been willing to introduce a performance penalty for
Python 2 users, but performance is such a critical issue for parsing I
couldn't justify it to myself.) This meant that I had to constrain my
implementation, while trying to incorporate forward-looking support
features (such as __bool__ and __dir__), which have no effect on older
Python versions, but support additions in newer Pythons. I just
couldn't get through on the python-dev list that I couldn't just
upgrade my code to 2.6 and then use 2to3 to keep in step across the
2-3 chasm, as this would leave behind my faithful pre-2.6 users.

Here are some of the methods I used:

- No use of sets. Instead I defined a very simple set simulation
using dict keys, which could be interchanged with set for later
versions.

- No generator expressions, only list comprehensions.

- No use of decorators. BUT, pyparsing includes a decorator method,
traceParseAction, which can be used by users with later Pythons as
@traceParseAction in their own code.

- No print statements. As pyparsing is intended to be an internal
module, it does no I/O as part of its function - it only processes a
given string, and returns a data structure.

- Python 2-3 compatible exception syntax. This may have been my
trickiest step. The change of syntax for except from

except ExceptionType, ex:

to:

except ExceptionType as ex:

is completely forward and backward incompatible. The workaround is to
rewrite as:

except ExceptionType:
ex = sys.exc_info()[0]

which works just fine in 2.x and 3.x. However, there is a slight
performance penalty in doing this, and pyparsing uses exceptions as
part of its grammar success/failure signalling and backtracking; I've
used this technique everywhere I can get away with it, but there is
one critical spot where I can't use it, so I have to keep 2 code bases
with slight differences between them.

- Implement __bool__, followed by __nonzero__ = __bool__. This will
give you boolean support for your classes in 2.3-3.1.

- Implement __dir__, which is unused by old Pythons, but supports
customization of dir() output for your own classes.

- Implement __len__, __contains__, __iter__ and __reversed__ for
container classes.

- No ternary expressions. Not too difficult really, there are several
well-known workarounds for this, either by careful use of and's and
or's, or using the bool-as-int to return the value from
(falseValue,trueValue)[condition].

- Define a version-sensitive portion of your module, to define
synonyms for constants that changed name between versions. Something
like:

_PY3K = sys.version_info[0] > 2
if _PY3K:
_MAX_INT = sys.maxsize
basestring = str
_str2dict = set
alphas = string.ascii_lowercase + string.ascii_uppercase
else:
_MAX_INT = sys.maxint
range = xrange
_str2dict = lambda strg : dict( [(c,0) for c in strg] )
alphas = string.lowercase + string.uppercase

The main body of my code uses range throughout (for example), and with
this definition I get the iterator behavior of xrange regardless of
Python version.


In the end I still have 2 source files, one for Py2 and one for Py3,
but there is only a small and manageable number of differences between
them, and I expect at some point I will move forward to supporting Py3
as my primary target version. But personally I think this overall
Python 2-3 migration process is moving along at a decent rate, and I
should be able to make my switchover in another 12-18 months. But in
the meantime, I am still able to support all versions of Python NOW,
and I plan to continue doing so (albeit "support" for 2.x versions
will eventually mean "continue to offer a frozen feature set, with
minimal bug-fixing if any").

I realize that pyparsing is a simple-minded module in comparison to
others: it is pure Python, so it has no issues with C extensions; it
does no I/O, so print-as-statement vs. print-as-function is not an
issue; and it imports few other modules, so the ones it does have not
been dropped in Py3; and overall it is only a few thousand lines of
code. But I just offer this post as a concrete data point in this
discussion.

-- Paul
 
P

Paul Rubin

Paul McGuire said:
is completely forward and backward incompatible. The workaround is to
rewrite as:

except ExceptionType:
ex = sys.exc_info()[0]

which works just fine in 2.x and 3.x.

Are you sure? I wonder if there might be some race condition that could
make it fail.

I didn't even know about (or forgot) this change. Yucch.
 
T

Thomas Jollans

Paul McGuire said:
is completely forward and backward incompatible. The workaround is to
rewrite as:

except ExceptionType:
ex = sys.exc_info()[0]

which works just fine in 2.x and 3.x.

Are you sure? I wonder if there might be some race condition that could
make it fail.

Luckily, no: (lib. docs on exc_info())

This function returns a tuple of three values that give information
about the exception that is currently being handled. The information
returned is specific both to the current thread and to the current stack
frame.
 
G

geremy condra

There is an existing 2to3 and other pages for Python code conversion. I do
not know of any for CAPI conversion. The need for such has been acknowledged
among the devs but if there is nothing yet, we need someone with specialized
experience and a bit of time to make a first draft. If you start one, give
it an easy to remember name C2to3? 2to3Capi? You choose. And link to it from
the 2to3 page

In his post on this thread, Martin Loewis volunteered to list what he knows
from psycopg2 if someone else will edit.

I'm not sure why I don't have this post, but I'm happy to help edit
etc if Martin
wants to put together a rough draft.

Geremy Condra
 
K

Kevin Walzer

That's the real issue, not parentheses on the "print" statement.
Where's the business case for moving to Python 3? It's not faster.
It doesn't do anything you can't do in Python 2.6. There's no
"killer app" for it. End of life for Python 2.x is many years away;
most server Linux distros aren't even shipping with 2.6 yet. How can a
business justify spending money on conversion to Python 3?

That's decision for each business to make. My guess is that many
businesses won't upgrade for some time, until the major
libraries/modules support Python 3. I don't plan to move to Python 3 for
at least a couple of years.
Python 3 is a nice cleanup of some legacy syntax issues. But
that's just not enough. Perl 6 is a nice cleanup of Perl 5, and
look how that went. Ten years on, it's not even mainstream, let
alone dominant.

The Perl analogy isn't really useful here. Perl 6 is somewhere between
the HURD and Duke Nukem Forever in terms of being viable. Even the Perl
website says, "If you are looking for production ready code please use
Perl 5." That's one reason why Perl 5 development has recently undergone
a resurgence.

Python 3, by contrast, is production-ready in itself; libraries are
gradually moving to support it, and Python 2 has a definite end-of-life
release in 2.7, with an extended maintenance period for 2.7. The Python
developers are providing a much stronger and clearer path forward for
Python 3. The transition period may last five years, but the path is clear.

As a Mac developer, I'm sympathetic to your frustration. A few years ago
Apple deprecated one of its major API's (Carbon), on which my own
development depended, and there was a lot of uncertainty about major
libraries that use Carbon being updated. This is normal in any
transition period. Eventually, the major libraries I depend on were
updated by their developers (i.e. ported to the Cocoa API), I was able
to migrate my own applications to the updated libraries, and life went on.

I think the same thing will happen with Python. It's useful to note the
libraries that are not yet ported to support Python 3, and to share best
practices for moving forward. Past a certain point, however, I don't see
much point in attacking the existence of Python 3 or questioning the
need to move toward Python 3. It's here, it's the way forward, and
that's not going to change. Might as well accept it.

--Kevin
 
R

Roy Smith

Kevin Walzer said:
That's decision for each business to make. My guess is that many
businesses won't upgrade for some time, until the major
libraries/modules support Python 3. I don't plan to move to Python 3 for
at least a couple of years.

It takes a long time for big businesses to upgrade. It's not like me or
you. I just download the latest and greatest, run the installer, and
I'm good to go.

A big company has to install it in a test lab, certify it, get approval
from IT, log a change request, etc.

You need to get approval from your manager, your director, your VP, and
so on up the management chain until you finally reach somebody who has
no clue what's going on and either sits on the request or denies it out
of ignorance. Or, more likely, you just hit some middle-management
layer where the guy doesn't have the authority to approve it himself,
and isn't willing to expend the political capital it would take to get
approval from the next layer up.

Somebody might decide they don't want to disturb any existing production
systems (not a bad idea, really), so you need to order new hardware for
it. Even if you can get capital approval for that, it mushrooms into
finding rack space, and the UPS is already oversubscribed, and so is the
cooling, and there's no available network ports, and so on. Suddenly,
downloading some free software has become a 5-figure project.

Big businesses have lots of ways to ensure that no progress is ever
made. If you think any of the above is made up, you've never worked for
a big company.
 
C

Carl Banks

One thing that would be very useful is how to maintain something that
works on 2.x and 3.x, but not limiting yourself to 2.6. Giving up
versions below 2.6 is out of the question for most projects with a
significant userbase IMHO. As such, the idea of running the python 3
warnings is not so useful IMHO - unless it could be made to work
better for python 2.x < 2.6, but I am not sure the idea even makes
sense.

This is exactly how I felt about my support for pyparsing, that I was
trying continue to provide support for 2.3 users, up through 3.x
users, with a single code base.  (This would actually have been
possible if I had been willing to introduce a performance penalty for
Python 2 users, but performance is such a critical issue for parsing I
couldn't justify it to myself.)  This meant that I had to constrain my
implementation, while trying to incorporate forward-looking support
features (such as __bool__ and __dir__), which have no effect on older
Python versions, but support additions in newer Pythons.  I just
couldn't get through on the python-dev list that I couldn't just
upgrade my code to 2.6 and then use 2to3 to keep in step across the
2-3 chasm, as this would leave behind my faithful pre-2.6 users.

Here are some of the methods I used:

- No use of sets.  Instead I defined a very simple set simulation
using dict keys, which could be interchanged with set for later
versions.

- No generator expressions, only list comprehensions.

- No use of decorators.  BUT, pyparsing includes a decorator method,
traceParseAction, which can be used by users with later Pythons as
@traceParseAction in their own code.

- No print statements.  As pyparsing is intended to be an internal
module, it does no I/O as part of its function - it only processes a
given string, and returns a data structure.

- Python 2-3 compatible exception syntax.  This may have been my
trickiest step.  The change of syntax for except from

    except ExceptionType, ex:

to:

    except ExceptionType as ex:

is completely forward and backward incompatible.  The workaround is to
rewrite as:

    except ExceptionType:
        ex = sys.exc_info()[0]

which works just fine in 2.x and 3.x.  However, there is a slight
performance penalty in doing this, and pyparsing uses exceptions as
part of its grammar success/failure signalling and backtracking; I've
used this technique everywhere I can get away with it, but there is
one critical spot where I can't use it, so I have to keep 2 code bases
with slight differences between them.

- Implement __bool__, followed by __nonzero__ = __bool__.  This will
give you boolean support for your classes in 2.3-3.1.

- Implement __dir__, which is unused by old Pythons, but supports
customization of dir() output for your own classes.

- Implement __len__, __contains__, __iter__ and __reversed__ for
container classes.

- No ternary expressions.  Not too difficult really, there are several
well-known workarounds for this, either by careful use of and's and
or's, or using the bool-as-int to return the value from
(falseValue,trueValue)[condition].

- Define a version-sensitive portion of your module, to define
synonyms for constants that changed name between versions.  Something
like:

    _PY3K = sys.version_info[0] > 2
    if _PY3K:
        _MAX_INT = sys.maxsize
        basestring = str
        _str2dict = set
        alphas = string.ascii_lowercase + string.ascii_uppercase
    else:
        _MAX_INT = sys.maxint
        range = xrange
        _str2dict = lambda strg : dict( [(c,0) for c in strg] )
        alphas = string.lowercase + string.uppercase

The main body of my code uses range throughout (for example), and with
this definition I get the iterator behavior of xrange regardless of
Python version.

In the end I still have 2 source files, one for Py2 and one for Py3,
but there is only a small and manageable number of differences between
them, and I expect at some point I will move forward to supporting Py3
as my primary target version.  But personally I think this overall
Python 2-3 migration process is moving along at a decent rate, and I
should be able to make my switchover in another 12-18 months.  But in
the meantime, I am still able to support all versions of Python NOW,
and I plan to continue doing so (albeit "support" for 2.x versions
will eventually mean "continue to offer a frozen feature set, with
minimal bug-fixing if any").

I realize that pyparsing is a simple-minded module in comparison to
others: it is pure Python, so it has no issues with C extensions; it
does no I/O, so print-as-statement vs. print-as-function is not an
issue; and it imports few other modules, so the ones it does have not
been dropped in Py3; and overall it is only a few thousand lines of
code.  But I just offer this post as a concrete data point in this
discussion.

Thanks for the helpful post. However it looks like, other than the
except syntax, all of these are things you're already doing to support
2.3 to 2.6, so it seems suggest supporting 3.1 and 2.6 is maybe a
little more work than supporting 2.3 and 2.6.

We all know that Python is quite successful even with a history of
backward-incompatible changes and feature additions and even minor
paradigm shifts. What I'm interested in is, what things about the 2
to 3 transition is harder than already exists?

From Paul's post it looks like not as much as you'd think--but as he
says it's a pretty simple package.


Carl Banks
 
B

Brendan Abel

One thing that would be very useful is how to maintain something that
The entire fact that 3.x was *designed* to be incompatible should tell
you that supporting 2.x and 3.x with a single code base is a bad idea,
except for the very smallest of projects. This is the point where a
project should fork and provide two different versions.
 
M

MRAB

Brendan said:
The entire fact that 3.x was *designed* to be incompatible should tell
you that supporting 2.x and 3.x with a single code base is a bad idea,
except for the very smallest of projects. This is the point where a
project should fork and provide two different versions.

I wouldn't say that 3.x was designed to be incompatible. It was designed
to tidy the language, and the incompatibilities are an unfortunate
result.
 
J

John Bokma

John Nagle said:
Python 3 is a nice cleanup of some legacy syntax issues. But
that's just not enough. Perl 6 is a nice cleanup of Perl 5,

Eh, I wouldn't call Perl 6 a "nice cleanup". It's much better to
consider it a new language with roots in Perl 5 (amongst others). Or
to quote from http://dev.perl.org/perl6/:

"Perl 5 and Perl 6 are two languages in the Perl family, but of
different lineages."
and look how that went. Ten years on, it's not even mainstream, let
alone dominant.

I don't think that's the point of Perl 6 (if one can even say such a
thing, that is). Right now, (I) think of Perl 6 as a test bed for features
that couldn't be put in Perl 5 in an easy manner. Or (I) think of it as a
programming language lab.

My best guess is that with coming Christmas there will be a Perl 6
comparable to Python 3. But huge disclaimer: I hardly follow Perl 6
development.
 
B

Brendan Abel

I wouldn't say that 3.x was designed to be incompatible. It was designed
to tidy the language, and the incompatibilities are an unfortunate
result.

You're missing the point, and arguing semantics. It's a good thing I
didn't misspell anything.

Python 3.x will continue to change. The incompatibilities between 3.x
and 2.x will only become more numerous. If your goal is to support
2.x, and 3.x, you'd be best supporting them separately.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top