~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to doc/developers/code-style.txt

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-05-18 13:02:52 UTC
  • mfrom: (5830.3.6 i18n-msgfmt)
  • Revision ID: pqm@pqm.ubuntu.com-20110518130252-ky96qcvzt6o0zg3f
(mbp) add build_mo command to setup.py (INADA Naoki)

Show diffs side-by-side

added added

removed removed

Lines of Context:
77
77
Python versions
78
78
===============
79
79
 
80
 
Bazaar supports Python from 2.6 through 2.7, and in the future we want to
81
 
support Python 3.  Avoid using language features added in
82
 
2.7, or features deprecated in Python 3.0.  (You can check v3
 
80
Bazaar supports Python from 2.4 through 2.6, and in the future we want to
 
81
support Python 2.7 and 3.0.  Avoid using language features added in 2.5,
 
82
2.6 or 2.7, or features deprecated in Python 3.0.  (You can check v3
83
83
compatibility using the ``-3`` option of Python2.6.)
84
84
 
 
85
Specifically:
 
86
 
 
87
* Don't use the ``with`` statement.
 
88
 
 
89
* Don't ``from . import``.
 
90
 
 
91
* Don't use ``try/except/finally``, which is not supported in Python2.4,
 
92
  use separate nested ``try/except`` and ``try/finally`` blocks.
 
93
 
85
94
 
86
95
hasattr and getattr
87
96
===================
180
189
   why in a comment.
181
190
 
182
191
1. Never rely on a ``__del__`` method running.  If there is code that
183
 
   must run, instead have a ``finally`` block or an ``addCleanup`` call an
184
 
   explicit ``close`` method.
 
192
   must run, do it from a ``finally`` block instead.
185
193
 
186
194
2. Never ``import`` from inside a ``__del__`` method, or you may crash the
187
195
   interpreter!!
188
196
 
189
 
3. Prior to bzr 2.4, we sometimes used to raise warnings from del methods
190
 
   that the object was not cleaned up or closed.  We no longer do this:
191
 
   failure to close the object doesn't cause a test failure; the warning
192
 
   appears an arbitrary long time after the problem occurred (the object
193
 
   being leaked); merely having a del method inhibits Python gc; the
194
 
   warnings appear to users and upset them; they can also break tests that
195
 
   are checking what appears on stderr.
196
 
   
197
 
In short, just don't use ``__del__``.
 
197
3. In some places we raise a warning from the destructor if the object
 
198
   has not been cleaned up or closed.  This is considered OK: the warning
 
199
   may not catch every case but it's still useful sometimes.
 
200
 
198
201
 
199
202
Cleanup methods
200
203
===============