Don't use contextlib where it is no longer necessary
authorBen Steffen <bds@mit.edu>
Tue, 26 Nov 2019 19:49:54 +0000 (14:49 -0500)
committerBen Steffen <bds@mit.edu>
Tue, 26 Nov 2019 19:49:54 +0000 (14:49 -0500)
python/invirt/config.py

index 03b6a2d..245464b 100644 (file)
@@ -1,7 +1,6 @@
 import json
 from invirt.common import *
 import os
-from contextlib import closing
 import yaml
 import re
 
@@ -59,7 +58,7 @@ def list_files():
 def load_master():
     config = dict()
     for filename in list_files():
-        with closing(open(filename)) as f:
+        with open(filename) as f:
             augment(config, yaml.load(f, loader))
     return config
 
@@ -112,7 +111,7 @@ def load(force_refresh = False):
         # lock with other concurrent reads).  This isolation is accomplished
         # using an atomic filesystem rename in the refreshing stage.
         try: 
-            with closing(open(cache_path)) as f:
+            with open(cache_path) as f:
                 ns.cfg = json.read(f.read())
         except: do_refresh = True
 
@@ -127,7 +126,7 @@ def load(force_refresh = False):
             with lock_file(lock_path):
                 ns.cfg = load_master()
                 try: 
-                    with closing(open(cache_path + '.tmp', 'w')) as f:
+                    with open(cache_path + '.tmp', 'w') as f:
                         f.write(json.write(ns.cfg))
                 except: pass # silent failure
                 else: os.rename(cache_path + '.tmp', cache_path)