Skip to content

Commit b65f4a8

Browse files
authored
PR: Address pylint's "consider-using-with" warnings (#20)
1 parent 977ca39 commit b65f4a8

File tree

4 files changed

+10
-12
lines changed

4 files changed

+10
-12
lines changed

Diff for: pylsp/plugins/flake8_lint.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@ def run_flake8(flake8_executable, args, document):
6868
try:
6969
cmd = [flake8_executable]
7070
cmd.extend(args)
71-
p = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE)
71+
p = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE) # pylint: disable=consider-using-with
7272
except IOError:
7373
log.debug("Can't execute %s. Trying with 'python -m flake8'", flake8_executable)
7474
cmd = ['python', '-m', 'flake8']
7575
cmd.extend(args)
76-
p = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE)
76+
p = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE) # pylint: disable=consider-using-with
7777
(stdout, stderr) = p.communicate(document.source.encode())
7878
if stderr:
7979
log.error("Error while running flake8 '%s'", stderr.decode())

Diff for: pylsp/plugins/pylint_lint.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,13 @@ def _run_pylint_stdio(pylint_executable, document, flags):
236236
cmd = [pylint_executable]
237237
cmd.extend(flags)
238238
cmd.extend(['--from-stdin', document.path])
239-
p = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE)
239+
p = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE) # pylint: disable=consider-using-with
240240
except IOError:
241241
log.debug("Can't execute %s. Trying with 'python -m pylint'", pylint_executable)
242242
cmd = ['python', '-m', 'pylint']
243243
cmd.extend(flags)
244244
cmd.extend(['--from-stdin', document.path])
245-
p = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE)
245+
p = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE) # pylint: disable=consider-using-with
246246
(stdout, stderr) = p.communicate(document.source.encode())
247247
if stderr:
248248
log.error("Error while running pylint '%s'", stderr.decode())

Diff for: test/plugins/test_flake8_lint.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ def using_const():
2121

2222

2323
def temp_document(doc_text, workspace):
24-
temp_file = tempfile.NamedTemporaryFile(mode='w', delete=False)
25-
name = temp_file.name
26-
temp_file.write(doc_text)
27-
temp_file.close()
24+
with tempfile.NamedTemporaryFile(mode='w', delete=False) as temp_file:
25+
name = temp_file.name
26+
temp_file.write(doc_text)
2827
doc = Document(uris.from_fs_path(name), workspace)
2928

3029
return name, doc

Diff for: test/plugins/test_pylint_lint.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@ def hello():
2828
@contextlib.contextmanager
2929
def temp_document(doc_text, workspace):
3030
try:
31-
temp_file = tempfile.NamedTemporaryFile(mode='w', delete=False)
32-
name = temp_file.name
33-
temp_file.write(doc_text)
34-
temp_file.close()
31+
with tempfile.NamedTemporaryFile(mode='w', delete=False) as temp_file:
32+
name = temp_file.name
33+
temp_file.write(doc_text)
3534
yield Document(uris.from_fs_path(name), workspace)
3635
finally:
3736
os.remove(name)

0 commit comments

Comments
 (0)