X-Git-Url: https://arthur.barton.de/gitweb/?a=blobdiff_plain;f=CODINGSTYLE;h=348a2f51340bfe3545b7f9477cde631343126e7c;hb=8ab02ae782a1bc6e28cd0719d66c8ae51920ade0;hp=69c2cfb99d5a63ddbfab2cf21e1203e61cbc294c;hpb=5d83043c64d60f9e71b0c1c6dc93824f68ee2cba;p=bup.git diff --git a/CODINGSTYLE b/CODINGSTYLE index 69c2cfb..348a2f5 100644 --- a/CODINGSTYLE +++ b/CODINGSTYLE @@ -43,7 +43,6 @@ explicitly add stack traces to any exceptions that are going to be re-raised by anything other than a no-argument raise (otherwise the stack trace will be lost):: - try: ... except ... as ex: @@ -52,11 +51,24 @@ stack trace will be lost):: ... raise pending_ex -If an exception is thrown from an exception handler, the pending +When an exception is thrown from an exception handler, the pending exception should be the `"context" `_ -of the new exception This can be accomplished via -``add_ex_ctx()``:: +of the new exception, which can be accomplished (portably) via +``pending_raise()``:: + + try: + ... + except ... as ex: + with pending_raise(ex): + clean_up() + +This should do roughly the same thing in Python 2 and Python 3, +throwing any exception from ``clean_up()`` after adding ex as the +``__context__`` if clean_up() throws, and throwing ``ex`` otherwise. + +If for some reason, you need more control, you can use +``add_ex_ctx()`` directly:: try: ... @@ -69,4 +81,5 @@ of the new exception This can be accomplished via raise add_ex_ctx(ex2, ex) raise -See the end of ``lib/bup/compat.py`` for a functional example. +See the end of ``lib/bup/compat.py`` for a functional example, and all +of this can be removed once we drop support for Python 2.