Opened 6 years ago

Closed 9 months ago

Last modified 9 months ago

#5519 enhancement closed fixed (fixed)

Failure should inherit from BaseException

Reported by: fijal Owned by: Amber Brown <hawkowl@…>
Priority: normal Milestone: PyPy-support
Component: core Keywords:
Cc: Branch:


According to glyph and exarkun, there is never ever a good reason to subclass a Failure, so it should not be a backwards incompatible change to make Failure a new style class.

Also, we can prohibit subclassing it in the first place *and* it makes pypy slightly faster.

Attachments (1)

failure.patch (882 bytes) - added by Vladimir Perić 6 years ago.

Download all attachments as: .zip

Change History (10)

comment:1 Changed 6 years ago by Jean-Paul Calderone

Some things to watch out for:

  1. The implementation of Failure.trap means Failure cannot just be an object subclass (you cannot raise arbitrary new-style instances, only classic instances and BaseException instances). Subclassing BaseException (or Exception) might be appropriate.
  2. Once Failure is an Exception of some sort, the tests for failure debug mode (TestDebugMode.setUp) need to change. It's not possible to assign to the __dict__ of an Exception subclass.
  3. CopyableFailure breaks and will need some adjustment.

comment:2 Changed 6 years ago by Vladimir Perić

Keywords: py3k added
Milestone: Python-3.x

This is also relevant for Python 3 support, as old-style classes are no longer supported.

Changed 6 years ago by Vladimir Perić

Attachment: failure.patch added

comment:3 Changed 6 years ago by Vladimir Perić

Right, so the attached patch changes Failure to inherit from BaseException and fixes the __dict__ issue with setattr and all of test_failure passes. The problem is in test_pbfailure, which just hangs... I've traced the hang to two tests, test_asynchronousException and test_asynchronousError but that's as far as I got... Not even sure what CopyableFailure is (yet!).

comment:4 Changed 9 months ago by Craig Rodrigues

Keywords: py3k removed

comment:5 Changed 9 months ago by Craig Rodrigues

Milestone: Python-3.xPyPy-support
Summary: Failure should become a new style classFailure should inherit from BaseException

comment:6 Changed 9 months ago by Craig Rodrigues

Keywords: review added

comment:7 Changed 9 months ago by Amber Brown <hawkowl@…>

Owner: set to Amber Brown <hawkowl@…>
Resolution: fixed
Status: newclosed

In 53922a2:

Merge 5519-rodrigc-vperic-failure-baseexception: Make twisted.python.failure.Failure inherit from BaseException

Authors: vperic, rodrigc
Reviewer: hawkowl
Fixes: ticket:5519

comment:8 Changed 9 months ago by hawkowl

Keywords: review removed

comment:9 Changed 9 months ago by Craig Rodrigues

test_pbfailure, test_asynchronousException and test_asynchronousError are not failing with this change

Note: See TracTickets for help on using tickets.