After some further reading, I found that PEP-352 (http://www.python.org/dev/peps/pep-0352/) explicitly states that "Including programmatic information (e.g., an error code number) should be stored as a separate attribute in a subclass [and not in the args attribute]." The parameter to Exception.__init__ should always be a single, human-readable string. The default pickler doesn't handle this officially-prescribed use-case without overriding __reduce__.
class F(Exception):
def __init__(self, message, code):
Exception.__init__(self, message)
self.code = code
Of course, as belopolsky observed, __repr__ must also be overridden. |