[rfc][patch] bzr on python2.5
Brian M. Carlson
sandals at crustytoothpaste.ath.cx
Fri Apr 28 19:10:32 BST 2006
I just installed python2.5 on my i386/sid system, and I wanted to try
out bzr with it. I've mostly found general classes of errors.
The first problem is that exceptions do not seem to export the args
attribute. This requires a super()-like[0] call from BzrNewError into
BzrError to create and populate the args attribute.
The second problem I've encountered is slightly more difficult.
Basically, several parts of the code use exception names in messages,
and several tests rely on a certain output format of exceptions. This
is also related to the change to new-style classes in python2.5. I
added a call to re.sub to remove the unwanted pieces.
The third problem is that certain repository tests assume that generator
objects are implicitly converted to list form when using len. In other
words, instead of len(foo()), where foo is a generator, use
len(list(foo())), which is what I think you wanted anyway.
The last problem, and the only one I have not solved yet, because I want
some feedback, is that in bzrlib/errors.py there is a docstring test
which uses sys.exc_type. Not only is sys.exc_type deprecated, it is
also not uniform between the two python versions (again due to the
old-style vs. new-style classes).
What I would recommend doing is using the trace code (specifically
format_exception_short()), which I have already modified to work with
the new exception format.
I have attached the patch to this message. It is the same as the
command bzr diff -r1685..1689 on my python2.5 branch[1]. If this should
get 2 +1s, then I will merge it into my ready-for-merge branch[2]. I do
not expect this to be included in 0.8, so consider accordingly. Also,
your co-operation in not saturating my cable modem line is appreciated.
bmc
[0] Since exceptions are classobjs (old-style or "classic" classes) in
python2.4 and types (new-style or "new" classes) in python2.5 and super
only works on new-style classes, I couldn't actually use super, so as
not to break compatibility with python2.4.
[1]
http://crustytoothpaste.ath.cx/~bmc/version-controlled/bzr/bzr/stonewall-debian/bmc-python2.5/
[2]
http://crustytoothpaste.ath.cx/~bmc/version-controlled/bzr/bzr/stonewall-debian/bmc-mainline/
-------------- next part --------------
=== modified file 'a/bzrlib/errors.py'
--- a/bzrlib/errors.py
+++ b/bzrlib/errors.py
@@ -74,6 +74,10 @@
class BzrError(StandardError):
+ def __init__(self, *args):
+ if not hasattr(self, 'args'):
+ self.args = args
+
def __str__(self):
# XXX: Should we show the exception class in
# exceptions that don't provide their own message?
@@ -97,7 +101,11 @@
# base classes should override the docstring with their human-
# readable explanation
- def __init__(self, **kwds):
+ def __init__(self, *args, **kwds):
+ # XXX: Use the underlying BzrError to always generate the args attribute
+ # if it doesn't exist. We can't use super here, because exceptions are
+ # old-style classes in python2.4 (but new in 2.5). --bmc, 20060426
+ BzrError.__init__(self, *args)
for key, value in kwds.items():
setattr(self, key, value)
=== modified file 'a/bzrlib/tests/repository_implementations/test_repository.py'
--- a/bzrlib/tests/repository_implementations/test_repository.py
+++ b/bzrlib/tests/repository_implementations/test_repository.py
@@ -149,9 +149,9 @@
tree = wt.branch.repository.revision_tree('revision-1')
self.assertEqual(list(tree.list_files()), [])
tree = wt.branch.repository.revision_tree(None)
- self.assertEqual(len(tree.list_files()), 0)
+ self.assertEqual(len(list(tree.list_files())), 0)
tree = wt.branch.repository.revision_tree(NULL_REVISION)
- self.assertEqual(len(tree.list_files()), 0)
+ self.assertEqual(len(list(tree.list_files())), 0)
def test_fetch(self):
# smoke test fetch to ensure that the convenience function works.
=== modified file 'a/bzrlib/trace.py'
--- a/bzrlib/trace.py
+++ b/bzrlib/trace.py
@@ -42,6 +42,7 @@
import sys
import os
+import re
import logging
import bzrlib
@@ -263,6 +264,9 @@
exc_info - typically an exception from sys.exc_info()
"""
exc_type, exc_object, exc_tb = exc_info
+ if exc_type is not None:
+ exc_type = re.sub("<class '([A-Za-z0-9_.]+)'>", r'\1',
+ str(exc_type), 1)
try:
if exc_type is None:
return '(no exception)'
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 481 bytes
Desc: This is a digitally signed message part
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060428/7691a71a/attachment.pgp
More information about the bazaar
mailing list