[Python-Dev] PEP for allowing 'raise NewException from None'

Ethan Furman ethan at stoneleaf.us
Mon Jan 30 05:51:29 CET 2012

Latest addition for PEP 409 has been sent.  Text follows:

Language Details

Currently, __context__ and __cause__ start out as None, and then get set
as exceptions occur.

To support 'from None', __context__ will stay as it is, but __cause__
will start out as False, and will change to None when the 'raise ...
from None' method is used.

If __cause__ is False the __context__ (if any) will be printed.

If __cause__ is None the __context__ will not be printed.

if __cause__ is anything else, __cause__ will be printed.

This has the benefit of leaving the __context__ intact for future
logging, querying, etc., while suppressing its display if it is not caught.

raise ... from ... is not disallowed outside a try block, but this
behavior is not guaranteed to remain.


Should that last disclaimer be there?  Should it be changed?


More information about the Python-Dev mailing list