[issue1692335] Fix exception pickling: Move initial args assignment to BaseException.__new__
Jason R. Coombs
report at bugs.python.org
Wed Sep 22 16:58:07 CEST 2010
Jason R. Coombs <jaraco at jaraco.com> added the comment:
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.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue1692335>
_______________________________________
More information about the Python-bugs-list
mailing list