[Python-Dev] PEP 409 - final? (original) (raw)

Ethan Furman ethan at stoneleaf.us
Thu Feb 2 01🔞08 CET 2012


Terry Reedy wrote:

It sounds like you are asking for a special class NoException(BaseException) to use as the marker.

Guido van Rossum wrote:

So what did you think of Terry Reedy's idea of using a special exception class?

Our table would then look like:

                __context__          __cause__

raise None NoException

reraise previous NoException

reraise from previous None | exception

It is certainly simpler than trying to force the use of both True and False. :)

The purist side of me thinks it's still slightly awkward; the practical side recognizes that there probably is not a perfect solution and thinks this is workable, and is willing to deal with the slight awkwardness to get 'from None' up and running. :)

The main reason for the effort in keeping the previous exception in context instead of just clobbering it is for custom error handlers, yes?

So here is a brief comparison of the two:

def complete_traceback(): ....

Actually, I got about three lines into that and realized that whatever cause is set to is completely irrelevant for that function: if context is not None, follow the chain; the only relevance cause has is when would it print? If it is a (valid) exception. And how do we know if it's valid?

 # True, False, None
 if isinstance(exc.__cause__, BaseException):
     print_exc(exc)

or if exc.cause not in (True, False, None): print_exc(exc)

vs

 # None, __NoException__ (forced to be an instance)
 if (exc.__cause__ is not None
 and not isinstance(exc.__cause__, __NoException__):
     print_exc(exc)

or # None, NoException (forced to stay a class) if exc.cause not in (None, NoException): print_exc(exc)

Having gone through all that, I'm equally willing to go either way (True/False/None or NoException).

Implementation questions for the NoException route:

  1. Do we want double underscores, or just a single one?

    I'm thinking double to mark it as special as opposed to private.

  2. This is a new exception class -- do we want to store the class itself in context, or it's instance? If its class, should we somehow disallow instantiation of it?

  3. Should it be an exception, or just inherit from object? Is it worth worrying about somebody trying to raise it, or raise from it?

  4. Is the name 'NoException' confusing?

Ethan



More information about the Python-Dev mailing list