Skip to content

Commit 0c80e1e

Browse files
[deprecation] Make 'OutputLine' require a fixed number of args
Co-authored-by: Daniël van Noord <[email protected]>
1 parent 7702955 commit 0c80e1e

File tree

3 files changed

+18
-95
lines changed

3 files changed

+18
-95
lines changed

doc/whatsnew/fragments/8474.internal

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Following a deprecation period, the ``OutputLine`` class now requires
2+
the right number of argument all the time. The functional output can be
3+
regenerated automatically to achieve that easily.
4+
5+
Refs #8474

pylint/testutils/output_line.py

+12-48
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
from __future__ import annotations
66

7-
import warnings
87
from collections.abc import Sequence
98
from typing import Any, NamedTuple, TypeVar
109

@@ -88,55 +87,20 @@ def from_csv(
8887
"""
8988
if isinstance(row, str):
9089
row = row.split(",")
91-
# noinspection PyBroadException
92-
# pylint: disable = too-many-try-statements
9390
try:
91+
line = int(row[1])
9492
column = cls._get_column(row[2])
95-
if len(row) == 5:
96-
# TODO: 3.0
97-
warnings.warn(
98-
"In pylint 3.0 functional tests expected output should always include the "
99-
"expected confidence level, expected end_line and expected end_column. "
100-
"An OutputLine should thus have a length of 8.",
101-
DeprecationWarning,
102-
stacklevel=2,
103-
)
104-
return cls(
105-
row[0],
106-
int(row[1]),
107-
column,
108-
None,
109-
None,
110-
row[3],
111-
row[4],
112-
UNDEFINED.name,
113-
)
114-
if len(row) == 6:
115-
# TODO: 3.0
116-
warnings.warn(
117-
"In pylint 3.0 functional tests expected output should always include the "
118-
"expected end_line and expected end_column. An OutputLine should thus have "
119-
"a length of 8.",
120-
DeprecationWarning,
121-
stacklevel=2,
122-
)
123-
return cls(
124-
row[0], int(row[1]), column, None, None, row[3], row[4], row[5]
125-
)
126-
if len(row) == 8:
127-
end_line = cls._get_py38_none_value(row[3], check_endline)
128-
end_column = cls._get_py38_none_value(row[4], check_endline)
129-
return cls(
130-
row[0],
131-
int(row[1]),
132-
column,
133-
cls._value_to_optional_int(end_line),
134-
cls._value_to_optional_int(end_column),
135-
row[5],
136-
row[6],
137-
row[7],
138-
)
139-
raise IndexError
93+
end_line = cls._value_to_optional_int(
94+
cls._get_py38_none_value(row[3], check_endline)
95+
)
96+
end_column = cls._value_to_optional_int(
97+
cls._get_py38_none_value(row[4], check_endline)
98+
)
99+
# symbol, line, column, end_line, end_column, node, msg, confidences
100+
assert len(row) == 8
101+
return cls(
102+
row[0], line, column, end_line, end_column, row[5], row[6], row[7]
103+
)
140104
except Exception: # pylint: disable=broad-except
141105
# We need this to not fail for the update script to work.
142106
return cls("", 0, 0, None, None, "", "", "")

tests/testutils/test_output_line.py

+1-47
Original file line numberDiff line numberDiff line change
@@ -134,57 +134,11 @@ def test_output_line_to_csv(confidence: Confidence, message: _MessageCallable) -
134134
)
135135

136136

137-
@pytest.mark.parametrize(
138-
"confidence,expected_confidence", [[None, "UNDEFINED"], ["INFERENCE", "INFERENCE"]]
139-
)
140-
def test_output_line_from_csv_deprecated(
141-
confidence: str | None, expected_confidence: str
142-
) -> None:
143-
"""Test that the OutputLine NamedTuple is instantiated correctly with from_csv.
144-
Test OutputLine's of length 5 or 6.
145-
"""
146-
if confidence:
147-
proper_csv = [
148-
"missing-docstring",
149-
"1",
150-
"2",
151-
"obj",
152-
"msg",
153-
confidence,
154-
]
155-
else:
156-
proper_csv = ["missing-docstring", "1", "2", "obj", "msg"]
157-
with pytest.warns(DeprecationWarning) as records:
158-
output_line = OutputLine.from_csv(proper_csv, True)
159-
assert len(records) == 1
160-
161-
expected_column = 2 if PY38_PLUS else 0
162-
assert output_line == OutputLine(
163-
symbol="missing-docstring",
164-
lineno=1,
165-
column=expected_column,
166-
end_lineno=None,
167-
end_column=None,
168-
object="obj",
169-
msg="msg",
170-
confidence=expected_confidence,
171-
)
172-
173-
174137
def test_output_line_from_csv() -> None:
175138
"""Test that the OutputLine NamedTuple is instantiated correctly with from_csv.
176139
Test OutputLine of length 8.
177140
"""
178-
proper_csv = [
179-
"missing-docstring",
180-
"1",
181-
"2",
182-
"1",
183-
"None",
184-
"obj",
185-
"msg",
186-
"HIGH",
187-
]
141+
proper_csv = ["missing-docstring", "1", "2", "1", "None", "obj", "msg", "HIGH"]
188142
expected_column = 2 if PY38_PLUS else 0
189143

190144
output_line = OutputLine.from_csv(proper_csv)

0 commit comments

Comments
 (0)