Skip to content

Commit

Permalink
Use contexts when opening files to avoid resource warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Larralde committed Jun 22, 2017
1 parent 14946b7 commit 2379baa
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions green/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,8 @@ class ConfigFile(object): # pragma: no cover

def __init__(self, filepath):
self.first = True
self.lines = open(filepath).readlines()
with open(filepath) as f:
self.lines = f.readlines()

# Python 2.7 (Older dot versions)
def readline(self):
Expand Down Expand Up @@ -385,7 +386,8 @@ def getConfig(filepath=None): # pragma: no cover
# Users are expected to put a [green] section
# only if they use setup.cfg
if filepath.endswith('setup.cfg'):
read_func(open(filepath))
with open(filepath) as f:
read_func(f)
else:
read_func(ConfigFile(filepath))

Expand Down

0 comments on commit 2379baa

Please sign in to comment.