# HG changeset patch # User Olivier Delalleau # Date 1284757096 14400 # Node ID 5783948b3f8c92d15b3276371f5c107db0a1e12b # Parent bc1b445e22fa8c7fd6fed6ca28fe426e1f173341 API_coding_style: Moved the point about how to raise exception since it is found in official documents diff -r bc1b445e22fa -r 5783948b3f8c doc/v2_planning/API_coding_style.txt --- a/doc/v2_planning/API_coding_style.txt Fri Sep 17 16:51:09 2010 -0400 +++ b/doc/v2_planning/API_coding_style.txt Fri Sep 17 16:58:16 2010 -0400 @@ -220,6 +220,18 @@ def f(array=[]): # Dangerous if `array` is modified down the road. ... + * Always raise an exception with ``raise MyException(args)`` where ``MyException`` + inherits from ``Exception``. This is required for compatibility across + all versions of Python. + + .. code-block:: python + + # Good. + raise NotImplementedError('The Pylearn team is too lazy.') + # Bad. + raise NotImplementedError, 'The Pylearn team is too lazy.' + raise 'The Pylearn team is too lazy to implement this.' + * Use a leading underscore '_' in names of internal attributes / methods, but avoid the double underscore '__' unless you know what you are doing. @@ -254,18 +266,6 @@ n_samples_per_split = n_samples / n_splits mean_x = sum(x) / len(x) - * Always raise an exception with ``raise MyException(args)`` where ``MyException`` - inherits from ``Exception``. This is required for compatibility across - all versions of Python. - - .. code-block:: python - - # Good. - raise NotImplementedError('The Pylearn team is too lazy.') - # Bad. - raise NotImplementedError, 'The Pylearn team is too lazy.' - raise 'The Pylearn team is too lazy to implement this.' - * Use either ``try ... except`` or ``try ... finally``, but do not mix ``except`` with ``finally`` (which is not supported in Python 2.4). You can however embed one into the other to mimic the ``try ... except ...