summaryrefslogtreecommitdiff
path: root/pylint
diff options
context:
space:
mode:
authorPierre Sassoulas <pierre.sassoulas@gmail.com>2021-10-27 11:31:33 +0200
committerGitHub <noreply@github.com>2021-10-27 11:31:33 +0200
commit1f77ff6135bc280a6cfd46fc3bd917d3436d55e2 (patch)
treea8619e4001e1b4d8bf2650b876caecdfa2e8766e /pylint
parent4007c8b3eb0b02c01332b191755cb12390c16eef (diff)
downloadpylint-git-1f77ff6135bc280a6cfd46fc3bd917d3436d55e2.tar.gz
Fix the deprecation of set_output in our code (#5209)
* Fix the deprecation of set_output in our code * Add a test for the deprecation warning itself * Refactor the set_output from the MultiReporter We can remove set_output declaration because the function was already failing with a NotImplementedError before, so removing it make it fail another way
Diffstat (limited to 'pylint')
-rw-r--r--pylint/lint/pylinter.py5
-rw-r--r--pylint/lint/run.py2
-rw-r--r--pylint/reporters/multi_reporter.py26
3 files changed, 17 insertions, 16 deletions
diff --git a/pylint/lint/pylinter.py b/pylint/lint/pylinter.py
index ae2126c09..ede27d1e8 100644
--- a/pylint/lint/pylinter.py
+++ b/pylint/lint/pylinter.py
@@ -618,16 +618,13 @@ class PyLinter(
reporter = self._load_reporter_by_name(reporter_name)
sub_reporters.append(reporter)
-
if reporter_output:
(reporter_output,) = reporter_output
-
# pylint: disable=consider-using-with
output_file = stack.enter_context(
open(reporter_output, "w", encoding="utf-8")
)
-
- reporter.set_output(output_file)
+ reporter.out = output_file
output_files.append(output_file)
# Extend the lifetime of all opened output files
diff --git a/pylint/lint/run.py b/pylint/lint/run.py
index 4348fd721..22c3dd14f 100644
--- a/pylint/lint/run.py
+++ b/pylint/lint/run.py
@@ -377,7 +377,7 @@ to search for configuration file.
if self._output:
try:
with open(self._output, "w", encoding="utf-8") as output:
- linter.reporter.set_output(output)
+ linter.reporter.out = output
linter.check(args)
score_value = linter.generate_reports()
except OSError as ex:
diff --git a/pylint/reporters/multi_reporter.py b/pylint/reporters/multi_reporter.py
index a6be1c1b8..f674a29e4 100644
--- a/pylint/reporters/multi_reporter.py
+++ b/pylint/reporters/multi_reporter.py
@@ -38,11 +38,24 @@ class MultiReporter:
):
self._sub_reporters = sub_reporters
self.close_output_files = close_output_files
-
self._path_strip_prefix = os.getcwd() + os.sep
self._linter: Optional[PyLinter] = None
+ self.out = output
- self.set_output(output)
+ @property
+ def out(self):
+ return self.__out
+
+ @out.setter
+ def out(self, output: Optional[AnyFile] = None):
+ """
+ MultiReporter doesn't have it's own output. This method is only
+ provided for API parity with BaseReporter and should not be called
+ with non-None values for 'output'.
+ """
+ self.__out = None
+ if output is not None:
+ raise NotImplementedError("MultiReporter does not support direct output.")
def __del__(self) -> None:
self.close_output_files()
@@ -66,15 +79,6 @@ class MultiReporter:
for rep in self._sub_reporters:
rep.handle_message(msg)
- # pylint: disable=no-self-use
- def set_output(self, output: Optional[AnyFile] = None) -> None:
- """set output stream"""
- # MultiReporter doesn't have it's own output. This method is only
- # provided for API parity with BaseReporter and should not be called
- # with non-None values for 'output'.
- if output is not None:
- raise NotImplementedError("MultiReporter does not support direct output.")
-
def writeln(self, string: str = "") -> None:
"""write a line in the output buffer"""
for rep in self._sub_reporters: