/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

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

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-05-27 07:23:00 UTC
  • mfrom: (5261.2.1 doc-explicit-file-close)
  • Revision ID: pqm@pqm.ubuntu.com-20100527072300-2ne7hfu800189v4q
(parthm) (parthm) added tip on explicit file closing to 'Portability Tips'
 section of code-style.txt (Parth Malwankar)

Show diffs side-by-side

added added

removed removed

Lines of Context:
341
341
=============
342
342
 
343
343
All code should be exercised by the test suite.  See the `Bazaar Testing
344
 
Guide <http://doc.bazaar-vcs.org/developers/testing.html>`_ for detailed
 
344
Guide <http://doc.bazaar.canonical.com/developers/testing.html>`_ for detailed
345
345
information about writing tests.
346
346
 
347
347
 
411
411
to fail on Windows if some files are readonly or still open elsewhere.
412
412
Use ``bzrlib.osutils.rmtree`` instead.
413
413
 
 
414
Using the ``open(..).read(..)`` or ``open(..).write(..)`` style chaining
 
415
of methods for reading or writing file content relies on garbage collection
 
416
to close the file which may keep the file open for an undefined period of
 
417
time. This may break some follow up operations like rename on Windows.
 
418
Use ``try/finally`` to explictly close the file. E.g.::
414
419
 
 
420
    f = open('foo.txt', 'w')
 
421
    try:
 
422
        f.write(s)
 
423
    finally:
 
424
        f.close()
415
425
 
416
426
..
417
427
   vim: ft=rst tw=74 ai