ga: add a pylint check to avoid adding open calls without encoding= (#48099)
This commit is contained in:

committed by
GitHub

parent
dd8dff7872
commit
af6526bb82
@@ -161,7 +161,7 @@ def _err_check(result, func, args):
|
||||
)
|
||||
# Use conout$ here to handle a redirectired stdout/get active console associated
|
||||
# with spack
|
||||
with open(r"\\.\CONOUT$", "w") as conout:
|
||||
with open(r"\\.\CONOUT$", "w", encoding="utf-8") as conout:
|
||||
# Link above would use kernel32.GetStdHandle(-11) however this would not handle
|
||||
# a redirected stdout appropriately, so we always refer to the current CONSOLE out
|
||||
# which is defined as conout$ on Windows.
|
||||
|
@@ -762,7 +762,7 @@ def __enter__(self):
|
||||
self.reader = open(self.logfile, mode="rb+")
|
||||
|
||||
# Dup stdout so we can still write to it after redirection
|
||||
self.echo_writer = open(os.dup(sys.stdout.fileno()), "w")
|
||||
self.echo_writer = open(os.dup(sys.stdout.fileno()), "w", encoding=sys.stdout.encoding)
|
||||
# Redirect stdout and stderr to write to logfile
|
||||
self.stderr.redirect_stream(self.writer.fileno())
|
||||
self.stdout.redirect_stream(self.writer.fileno())
|
||||
|
@@ -506,9 +506,7 @@ def test_filter_files_with_different_encodings(regex, replacement, filename, tmp
|
||||
# This should not raise exceptions
|
||||
fs.filter_file(regex, replacement, target_file, **keyword_args)
|
||||
# Check the strings have been replaced
|
||||
extra_kwargs = {"errors": "surrogateescape"}
|
||||
|
||||
with open(target_file, mode="r", **extra_kwargs) as f:
|
||||
with open(target_file, mode="r", encoding="utf-8", errors="surrogateescape") as f:
|
||||
assert replacement in f.read()
|
||||
|
||||
|
||||
@@ -558,9 +556,7 @@ def test_filter_files_multiple(tmpdir):
|
||||
fs.filter_file(r"\<string.h\>", "<unistd.h>", target_file)
|
||||
fs.filter_file(r"\<stdio.h\>", "<unistd.h>", target_file)
|
||||
# Check the strings have been replaced
|
||||
extra_kwargs = {"errors": "surrogateescape"}
|
||||
|
||||
with open(target_file, mode="r", **extra_kwargs) as f:
|
||||
with open(target_file, mode="r", encoding="utf-8", errors="surrogateescape") as f:
|
||||
assert "<malloc.h>" not in f.read()
|
||||
assert "<string.h>" not in f.read()
|
||||
assert "<stdio.h>" not in f.read()
|
||||
|
@@ -23,7 +23,7 @@ def _impl(spec_like, module_set_name="default", explicit=True):
|
||||
generator = writer_cls(spec, module_set_name, explicit)
|
||||
generator.write(overwrite=True)
|
||||
written_module = pathlib.Path(generator.layout.filename)
|
||||
content = written_module.read_text().splitlines()
|
||||
content = written_module.read_text(encoding="utf-8").splitlines()
|
||||
generator.remove()
|
||||
return content
|
||||
|
||||
|
@@ -203,7 +203,7 @@ def process_cmd_output(out, err):
|
||||
|
||||
def streamify(arg, mode):
|
||||
if isinstance(arg, str):
|
||||
return open(arg, mode), True
|
||||
return open(arg, mode), True # pylint: disable=unspecified-encoding
|
||||
elif arg in (str, str.split):
|
||||
return subprocess.PIPE, False
|
||||
else:
|
||||
|
Reference in New Issue
Block a user