X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=CODINGSTYLE;h=0344157516773c0e1709fb07484c9e8b18408217;hb=73f4b83af6c73a0ba48e448883856bf24aacbf7d;hp=12879e56b1873f06264aaa6d54021d78dc139f9b;hpb=6b9a8dc93e462c93408848470e3552ed10a5cce4;p=bup.git diff --git a/CODINGSTYLE b/CODINGSTYLE index 12879e5..0344157 100644 --- a/CODINGSTYLE +++ b/CODINGSTYLE @@ -1,7 +1,14 @@ .. -*-rst-*- -General -======= +C += + +The C implementations should follow the `kernel/git coding style +`_. + + +Python +====== Python code follows `PEP8 `_ with regard to coding style and `PEP257 @@ -23,5 +30,42 @@ blank line in between). Here's an example from Module-level docstrings follow exactly the same guidelines but without the blank line between the summary and the details. -The C implementations should follow the `kernel/git coding style -`_. + +Exception Handling +------------------ + +Avoid finally: blocks in favor of explict catches because a throw +from a finally block will lose any pending exception. An explicit +catch can chain it (see below). + +To behave similarly under Python 2 and 3, use add_ex_tb() to +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: + add_ex_tb(ex) + pending_ex = ex + ... + raise pending_ex + +If 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()``:: + + try: + ... + except ... as ex: + add_ex_tb(ex) + try: + ... + except ... as ex2: + add_ex_tb(ex2) + raise add_ex_ctx(ex2, ex) + +See the end of ``lib/bup/compat.py`` for a functional example.