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

................
  r81226 | victor.stinner | 2010-05-16 02:36:38 +0200 (dim., 16 mai 2010) | 11 lines

  Merged revisions 81224 via svnmerge from
  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 e2889cca6d2df43aaea9bdf8bf62c44073a7da94..12f4e8f6508cd57731cb6d128b638fcceadcc345 100644 (file)
@@ -66,13 +66,11 @@ class CommonTest(seq_tests.CommonTest):
         d.append(d)
         d.append(400)
         try:
-            fo = open(support.TESTFN, "w")
-            fo.write(str(d))
-            fo.close()
-            fo = open(support.TESTFN, "r")
-            self.assertEqual(fo.read(), repr(d))
+            with open(support.TESTFN, "w") as fo:
+                fo.write(str(d))
+            with open(support.TESTFN, "r") as fo:
+                self.assertEqual(fo.read(), repr(d))
         finally:
-            fo.close()
             os.remove(support.TESTFN)
 
     def test_set_subscript(self):