~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

(gz) Fix test failure on alpha by correcting format string for
 gc_chk_sha1_record (Martin [gz])

Show diffs side-by-side

added added

removed removed

Lines of Context:
189
189
   why in a comment.
190
190
 
191
191
1. Never rely on a ``__del__`` method running.  If there is code that
192
 
   must run, instead have a ``finally`` block or an ``addCleanup`` call an
193
 
   explicit ``close`` method.
 
192
   must run, do it from a ``finally`` block instead.
194
193
 
195
194
2. Never ``import`` from inside a ``__del__`` method, or you may crash the
196
195
   interpreter!!
197
196
 
198
 
3. Prior to bzr 2.4, we sometimes used to raise warnings from del methods
199
 
   that the object was not cleaned up or closed.  We no longer do this:
200
 
   failure to close the object doesn't cause a test failure; the warning
201
 
   appears an arbitrary long time after the problem occurred (the object
202
 
   being leaked); merely having a del method inhibits Python gc; the
203
 
   warnings appear to users and upset them; they can also break tests that
204
 
   are checking what appears on stderr.
205
 
   
206
 
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
 
207
201
 
208
202
Cleanup methods
209
203
===============