Skip to content

Commit

Permalink
Update pylint to conform to unspecified-encoding
Browse files Browse the repository at this point in the history
With addition of the unspecified-encoding checker calls of open()
need an encoding argument.
Where necessary this argument has been added.
  • Loading branch information
DanielNoord committed Jul 28, 2021
1 parent 8e7ce74 commit 7296334
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pylint/checkers/similar.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ def Run(argv=None):
min_lines, ignore_comments, ignore_docstrings, ignore_imports, ignore_signatures
)
for filename in args:
with open(filename) as stream:
with open(filename, encoding="utf-8") as stream:
sim.append_stream(filename, stream)
sim.run()
sys.exit(0)
Expand Down
2 changes: 1 addition & 1 deletion pylint/checkers/spelling.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def open(self):
dict_name, self.config.spelling_private_dict_file
)
self.private_dict_file = open( # pylint: disable=consider-using-with
self.config.spelling_private_dict_file, "a"
self.config.spelling_private_dict_file, "a", encoding="utf-8"
)
else:
self.spelling_dict = enchant.Dict(dict_name)
Expand Down
2 changes: 1 addition & 1 deletion pylint/config/find_default_config_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


def _toml_has_config(path):
with open(path) as toml_handle:
with open(path, encoding="utf-8") as toml_handle:
try:
content = toml.load(toml_handle)
except TomlDecodeError as error:
Expand Down
2 changes: 1 addition & 1 deletion pylint/config/option_manager_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def read_config_file(self, config_file=None, verbose=None):
parser = self.cfgfile_parser

if config_file.endswith(".toml"):
with open(config_file) as fp:
with open(config_file, encoding="utf-8") as fp:
content = toml.load(fp)

try:
Expand Down
9 changes: 6 additions & 3 deletions pylint/lint/pylinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,9 @@ def _load_reporters(self) -> None:
(reporter_output,) = reporter_output

# pylint: disable=consider-using-with
output_file = stack.enter_context(open(reporter_output, "w"))
output_file = stack.enter_context(
open(reporter_output, "w", encoding="utf-8")
)

reporter.set_output(output_file)
output_files.append(output_file)
Expand Down Expand Up @@ -617,8 +619,9 @@ def set_option(self, optname, value, action=None, optdict=None):
except KeyError:
meth = self._bw_options_methods[optname]
warnings.warn(
"%s is deprecated, replace it by %s"
% (optname, optname.split("-")[0]),
"{} is deprecated, replace it by {}".format(
optname, optname.split("-")[0]
),
DeprecationWarning,
)
value = utils._check_csv(value)
Expand Down
2 changes: 1 addition & 1 deletion pylint/lint/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ def __init__(

if self._output:
try:
with open(self._output, "w") as output:
with open(self._output, "w", encoding="utf-8") as output:
linter.reporter.set_output(output)
linter.check(args)
score_value = linter.generate_reports()
Expand Down
2 changes: 1 addition & 1 deletion pylint/pyreverse/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def get_default_options():
if home:
rcfile = os.path.join(home, RCFILE)
try:
with open(rcfile) as file_handle:
with open(rcfile, encoding="utf-8") as file_handle:
options = file_handle.read().split()
except OSError:
pass # ignore if no config file found
Expand Down
4 changes: 3 additions & 1 deletion pylint/pyreverse/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ def __init__(self, config):

def set_printer(self, file_name, basename):
"""initialize VCGWriter for a UML graph"""
self.graph_file = open(file_name, "w+") # pylint: disable=consider-using-with
self.graph_file = open( # pylint: disable=consider-using-with
file_name, "w+", encoding="utf-8"
)
self.printer = VCGPrinter(self.graph_file)
self.printer.open_graph(
title=basename,
Expand Down
4 changes: 2 additions & 2 deletions pylint/testutils/lint_module_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,14 @@ def multiset_difference(
# pylint: disable=consider-using-with
def _open_expected_file(self):
try:
return open(self._test_file.expected_output)
return open(self._test_file.expected_output, encoding="utf-8")
except FileNotFoundError:
return StringIO("")

# pylint: disable=consider-using-with
def _open_source_file(self):
if self._test_file.base == "invalid_encoded_data":
return open(self._test_file.source)
return open(self._test_file.source, encoding="utf-8")
if "latin1" in self._test_file.base:
return open(self._test_file.source, encoding="latin1")
return open(self._test_file.source, encoding="utf8")
Expand Down

0 comments on commit 7296334

Please sign in to comment.