Address consider-using-with.

This commit is contained in:
Felix Fontein 2025-10-25 01:41:59 +02:00
parent 40c240ac2b
commit ecb2d8b01e
3 changed files with 39 additions and 37 deletions

View File

@ -379,7 +379,6 @@ disable=raw-checker-failed,
wrong-import-order, wrong-import-order,
wrong-import-position, wrong-import-position,
# To clean up: # To clean up:
consider-using-with,
fixme, fixme,
import-error, # TODO figure out why pylint cannot find the module import-error, # TODO figure out why pylint cannot find the module
no-name-in-module, # TODO figure out why pylint cannot find the module no-name-in-module, # TODO figure out why pylint cannot find the module

View File

@ -525,6 +525,7 @@ class Connection(ConnectionBase):
) )
args = [to_bytes(i, errors="surrogate_or_strict") for i in args] args = [to_bytes(i, errors="surrogate_or_strict") for i in args]
try: try:
# pylint: disable-next=consider-using-with
p = subprocess.Popen( p = subprocess.Popen(
args, stdin=in_file, stdout=subprocess.PIPE, stderr=subprocess.PIPE args, stdin=in_file, stdout=subprocess.PIPE, stderr=subprocess.PIPE
) )
@ -587,6 +588,7 @@ class Connection(ConnectionBase):
to_bytes(actual_out_path, errors="surrogate_or_strict"), "wb" to_bytes(actual_out_path, errors="surrogate_or_strict"), "wb"
) as out_file: ) as out_file:
try: try:
# pylint: disable-next=consider-using-with
pp = subprocess.Popen( pp = subprocess.Popen(
args, args,
stdin=subprocess.PIPE, stdin=subprocess.PIPE,

View File

@ -97,8 +97,10 @@ def create_archive(
) -> t.IO[bytes]: ) -> t.IO[bytes]:
extra_files = extra_files or [] extra_files = extra_files or []
if not fileobj: if not fileobj:
# pylint: disable-next=consider-using-with
fileobj = tempfile.NamedTemporaryFile() fileobj = tempfile.NamedTemporaryFile()
tarf = tarfile.open(mode="w:gz" if gzip else "w", fileobj=fileobj)
with tarfile.open(mode="w:gz" if gzip else "w", fileobj=fileobj) as tarf:
if files is None: if files is None:
files = build_file_list(root) files = build_file_list(root)
extra_names = set(e[0] for e in extra_files) extra_names = set(e[0] for e in extra_files)
@ -139,7 +141,6 @@ def create_archive(
info.size = len(contents_encoded) info.size = len(contents_encoded)
tarf.addfile(info, io.BytesIO(contents_encoded)) tarf.addfile(info, io.BytesIO(contents_encoded))
tarf.close()
fileobj.seek(0) fileobj.seek(0)
return fileobj return fileobj