Opened 5 years ago

Last modified 5 years ago

#5519 enhancement new

Failure should become a new style class

Reported by: fijal Owned by:
Priority: normal Milestone: Python-3.x
Component: core Keywords: py3k
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ć 5 years ago.

Download all attachments as: .zip

Change History (4)

comment:1 Changed 5 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 5 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 5 years ago by Vladimir Perić

Attachment: failure.patch added

comment:3 Changed 5 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!).

Note: See TracTickets for help on using tickets.