Skip to content

Commit

Permalink
qa: Use context managers where it makes sense
Browse files Browse the repository at this point in the history
Spotted by the latest version of pylint.
  • Loading branch information
dbaty committed May 18, 2021
1 parent 1e826d5 commit 351f179
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/cogite/checks/pre_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@


def run_command(command):
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
process.wait()
return b"".join(process.stdout.readlines()).decode(sys.stdout.encoding)
with subprocess.Popen(command, shell=True, stdout=subprocess.PIPE) as process:
process.wait()
return b"".join(process.stdout.readlines()).decode(sys.stdout.encoding)


def check_commits(
Expand Down
8 changes: 4 additions & 4 deletions src/cogite/interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ def input_from_file(starting_text=''):
path = pathlib.Path(tmp.name)
path.write_text(starting_text)

process = subprocess.Popen(f"$EDITOR {path}", shell=True)
process.wait()
with subprocess.Popen(f"$EDITOR {path}", shell=True) as process:
process.wait()

if process.returncode != os.EX_OK:
return None
if process.returncode != os.EX_OK:
return None

return path.read_text()

Expand Down
1 change: 1 addition & 0 deletions src/cogite/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def send(method, url, query=None, data=None, json=None, headers=None):
method=method,
)
try:
# pylint: disable=consider-using-with
return urllib.request.urlopen(request, timeout=TIMEOUT)
except urllib.error.HTTPError as exc:
content = exc.file.read().decode('utf-8')
Expand Down

0 comments on commit 351f179

Please sign in to comment.