Python ugliness |
2009-11-28
|
I usually tend to think of Python as the discerning gentleman's programming language: well-behaved, well-documented, people take care of the code written. I like the batteries-included approach and assume that the battery code in the standard library is well-written. "import this" is a vision statement directly included in the language - it's hard to get more stylish than that.
I got an eye-opener this weekend however. I was still on my quest to get desktopcouch and ubuntuone working on Fedora. While wresting with this bug and doing things that I usually consider a hanging offense (changing /usr-installed code by adding prints to figure out where the craziness was coming from) I finally drilled down to the exception-raising reason. It all boiled down to a single line of code in httplib.py:
def __init__(self, host, port=None, key_file=None, cert_file=None,
strict=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT):
where socket.py contains
_GLOBAL_DEFAULT_TIMEOUT = object()
So, in a nutshell, httplib2.py tracebacks because of this new object, which isn't a valid argument to sock.settimeout()
Now, I'm pretty sure I'm running into this problem because I'm doing "bad" things to some of the stdlib, pulling in bits I need to make ubuntuone (coded on a 2.6.3 python where my Fedora 11 comes with 2.6) work.
But pulling the cover off like this did point out this one object that:
- seems to be intended to be private, but it gets referenced from other stdlib modules
- comes with no documentation at all
- comes with not a single comment explaining *why* it's there, or *why* it's ok to just create a completely empty and useless "object" that you can't even trace the origin of (I had to override __setattr__ on some class to figure out what the anonymous object was, and where it was being set from, to find it)
Maybe I'm oldfashioned, but this leaves me disappointed. This one line breaks beauty, explicitness, and readability that is included in the Zen of Python.
The only attempt at explaining I found is this.
Any Python guru want to set me straight on why this isn't the incredibly ugly wart on stdlib that I consider it to be ?
Meanwhile I'll go digging in svn to see when it was added to 2.6 and why.