[Python-Dev] PEP for allowing 'raise NewException from None' (original) (raw)
Ethan Furman ethan at stoneleaf.us
Sat Jan 28 19:56:57 CET 2012
- Previous message: [Python-Dev] PEP for allowing 'raise NewException from None'
- Next message: [Python-Dev] PEP for allowing 'raise NewException from None'
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Nick Coghlan wrote:
On Sat, Jan 28, 2012 at 10:33 AM, Ethan Furman <ethan at stoneleaf.us> wrote:
So the question is:
- should 'raise ... from ...' be legal outside a try block? - should 'raise ... from None' be legal outside a try block? Given that it would be quite a bit of work to make it illegal, my preference is to leave it alone. I believe that means there's only one open question. Should "raise ex from None" be syntactic sugar for: 1. clearing the current thread's exception state (as I believe Ethan's patch currently does), thus meaning that context and cause both end up being None 2. setting cause to None (so that context still gets set normally, as it is now when cause is set to a specific exception), and having cause default to a new sentinel object that indicates "use context" I've already stated my own preference in favour of 2 - that approach means developers that think about it can explicitly change exception types such that the context isn't displayed by default, but application and framework developers remain free to insert their own exception handlers that always report the full exception stack.
The reasoning behind choice two makes a lot of sense. My latest effort (I should be able to get the patch posted within two days) involves creating a new dummy exception, SuppressContext, and 'raise ... from None' sets cause to it; the printing logic checks to see if cause is SuppressContext, and if so, prints neither context nor cause.
Not exactly how Nick describes it, but as far as I've gotten in my Python core hacking skills. ;)
Ethan
- Previous message: [Python-Dev] PEP for allowing 'raise NewException from None'
- Next message: [Python-Dev] PEP for allowing 'raise NewException from None'
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]