comparison doc/v2_planning/API_coding_style.txt @ 1254:705795076efd

API_coding_style: Added recommendation about how classes should derive from object
author Olivier Delalleau <delallea@iro>
date Fri, 24 Sep 2010 12:17:57 -0400
parents 23f63ecf0a9a
children b5673b32e8ec
comparison
equal deleted inserted replaced
1253:826d78f0135f 1254:705795076efd
216 ... 216 ...
217 # Bad. 217 # Bad.
218 def f(array=[]): # Dangerous if `array` is modified down the road. 218 def f(array=[]): # Dangerous if `array` is modified down the road.
219 ... 219 ...
220 220
221 * All top-level classes should inherit from ``object``. It makes some
222 'under-the-hood' differences that can be very useful for Python black
223 magic adepts.
224
225 .. code-block:: python
226
227 # Good.
228 class MyClass(object):
229 pass
230 # Bad.
231 class MyClass:
232 pass
233
221 * Always raise an exception with ``raise MyException(args)`` where ``MyException`` 234 * Always raise an exception with ``raise MyException(args)`` where ``MyException``
222 inherits from ``Exception``. This is required for compatibility across 235 inherits from ``Exception``. This is required for compatibility across
223 all versions of Python. 236 all versions of Python.
224 237
225 .. code-block:: python 238 .. code-block:: python