]> granicus.if.org Git - python/commitdiff
Merged revisions 81224 via svnmerge from
authorVictor Stinner <victor.stinner@haypocalc.com>
Sun, 16 May 2010 00:35:43 +0000 (00:35 +0000)
committerVictor Stinner <victor.stinner@haypocalc.com>
Sun, 16 May 2010 00:35:43 +0000 (00:35 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r81224 | victor.stinner | 2010-05-16 02:34:40 +0200 (dim., 16 mai 2010) | 4 lines

  Use with open() as fo: ... instead of try: fo = open(...) finally: fo.close()

  fo is not set if the open() fails.
........

Lib/test/list_tests.py

index 8dd6de634e25cdf3a862911772dde4e4907ded30..9168cfcc2c3cddfec60e1965423bfae1a162b764 100644 (file)
@@ -57,13 +57,11 @@ class CommonTest(seq_tests.CommonTest):
         d.append(d)
         d.append(400)
         try:
-            fo = open(test_support.TESTFN, "wb")
-            print >> fo, d,
-            fo.close()
-            fo = open(test_support.TESTFN, "rb")
-            self.assertEqual(fo.read(), repr(d))
+            with open(test_support.TESTFN, "wb") as fo:
+                print >> fo, d,
+            with open(test_support.TESTFN, "rb") as fo:
+                self.assertEqual(fo.read(), repr(d))
         finally:
-            fo.close()
             os.remove(test_support.TESTFN)
 
     def test_set_subscript(self):