On Oct 19, 2011, at 1:22 PM, Antoine Pitrou wrote:
On Wed, 19 Oct 2011 13:10:22 -0400
"Itamar Turner-Trauring" <
itamar@itamarst.org> wrote:
For example, I could post the
following patch for t.p.failure, but would you accept it?
@@ -464,6 +468,14 @@ class Failure:
# added 2003-06-23. See comment above in __init__
c['tb'] = None
+ try:
+ # Clear other references held by exception objects
+ c['value'].__cause__ = None
+ c['value'].__context__ = None
+ c['value'].__traceback__ = None
+ except AttributeError:
+ pass
+
if self.stack is not None:
# XXX: This is a band-aid. I can't figure out where these
# (failure.stack is None) instances are coming from.
That sort of patch would probably be fine, though I'd much rather that be
inside an if statement that checked the Python version rather than inside
a try/except. Faster, and much clearer what's going on.
The try/except is necessary because Failures sometimes wrap something
else than an exception, and where setting an arbitrary attribute is not
allowed.
This patch would definitely need to be accepted if you expect Twisted to eventually support Python 3. Why do you believe it wouldn't be accepted?
Of course it would need to have some test coverage - but a first step there is to have a buildbot actually running the tests on py3k.
Also: if Failures wrap something other than an Exception, that's a bug. in Failure.__doc__, it says: "@ivar value: The exception instance responsible for this failure." If there are cases where non-Exceptions are passed here, then perhaps that behavior should be deprecated before it raises an exception, but something needs to be adjusted so that the documentation is consistent with the implementation.
-glyph