[Python-checkins] r81226 - in python/branches/py3k: Lib/test/list_tests.py

victor.stinner python-checkins at python.org
Sun May 16 02:36:38 CEST 2010


Author: victor.stinner
Date: Sun May 16 02:36:38 2010
New Revision: 81226

Log:
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.
........


Modified:
   python/branches/py3k/   (props changed)
   python/branches/py3k/Lib/test/list_tests.py

Modified: python/branches/py3k/Lib/test/list_tests.py
==============================================================================
--- python/branches/py3k/Lib/test/list_tests.py	(original)
+++ python/branches/py3k/Lib/test/list_tests.py	Sun May 16 02:36:38 2010
@@ -66,13 +66,11 @@
         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):


More information about the Python-checkins mailing list