Skip to content

Commit d4e78f0

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

File tree

3 files changed

+19
-128
lines changed

3 files changed

+19
-128
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

+13-55
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

@@ -89,63 +88,22 @@ def from_csv(
8988
"""
9089
if isinstance(row, str):
9190
row = row.split(",")
92-
# noinspection PyBroadException
93-
# pylint: disable = too-many-try-statements
9491
try:
92+
line = int(row[1])
9593
column = cls._get_column(row[2])
96-
if len(row) == 5:
97-
# TODO: 3.0
98-
warnings.warn(
99-
"In pylint 3.0 functional tests expected output should always include the "
100-
"expected confidence level, expected end_line and expected end_column. "
101-
"An OutputLine should thus have a length of 8.",
102-
DeprecationWarning,
103-
stacklevel=2,
104-
)
105-
return cls(
106-
row[0],
107-
int(row[1]),
108-
column,
109-
None,
110-
None,
111-
row[3],
112-
row[4],
113-
UNDEFINED.name,
114-
)
115-
if len(row) == 6:
116-
# TODO: 3.0
117-
warnings.warn(
118-
"In pylint 3.0 functional tests expected output should always include the "
119-
"expected end_line and expected end_column. An OutputLine should thus have "
120-
"a length of 8.",
121-
DeprecationWarning,
122-
stacklevel=2,
123-
)
124-
return cls(
125-
row[0], int(row[1]), column, None, None, row[3], row[4], row[5]
126-
)
127-
if len(row) == 8:
128-
end_line = cls._get_py38_none_value(row[3], check_endline)
129-
end_column = cls._get_py38_none_value(row[4], check_endline)
130-
return cls(
131-
row[0],
132-
int(row[1]),
133-
column,
134-
cls._value_to_optional_int(end_line),
135-
cls._value_to_optional_int(end_column),
136-
row[5],
137-
row[6],
138-
row[7],
139-
)
140-
raise IndexError
141-
except Exception: # pylint: disable=broad-except
142-
warnings.warn(
143-
"Expected 'msg-symbolic-name:42:27:MyClass.my_function:The message:"
144-
f"CONFIDENCE' but we got '{':'.join(row)}'. Try updating the expected"
145-
f" output with:\npython tests/test_functional.py {UPDATE_OPTION}",
146-
UserWarning,
147-
stacklevel=2,
94+
end_line = cls._value_to_optional_int(
95+
cls._get_py38_none_value(row[3], check_endline)
96+
)
97+
end_column = cls._value_to_optional_int(
98+
cls._get_py38_none_value(row[4], check_endline)
14899
)
100+
# symbol, line, column, end_line, end_column, node, msg, confidences
101+
assert len(row) == 8
102+
return cls(
103+
row[0], line, column, end_line, end_column, row[5], row[6], row[7]
104+
)
105+
except Exception: # pylint: disable=broad-except
106+
# We need this to not fail for the update script to work.
149107
return cls("", 0, 0, None, None, "", "", "")
150108

151109
def to_csv(self) -> tuple[str, str, str, str, str, str, str, str]:

tests/testutils/test_output_line.py

+1-73
Original file line numberDiff line numberDiff line change
@@ -133,83 +133,11 @@ def test_output_line_to_csv(confidence: Confidence, message: _MessageCallable) -
133133
confidence.name,
134134
)
135135

136-
137-
def test_output_line_from_csv_error() -> None:
138-
"""Test that errors are correctly raised for incorrect OutputLine's."""
139-
# Test a csv-string which does not have a number for line and column
140-
with pytest.warns(
141-
UserWarning,
142-
match="msg-symbolic-name:42:27:MyClass.my_function:The message",
143-
):
144-
OutputLine.from_csv("'missing-docstring', 'line', 'column', 'obj', 'msg'", True)
145-
# Test a tuple which does not have a number for line and column
146-
with pytest.warns(
147-
UserWarning, match="we got 'missing-docstring:line:column:obj:msg'"
148-
):
149-
csv = ("missing-docstring", "line", "column", "obj", "msg")
150-
OutputLine.from_csv(csv, True)
151-
# Test a csv-string that is too long
152-
with pytest.warns(
153-
UserWarning,
154-
match="msg-symbolic-name:42:27:MyClass.my_function:The message",
155-
):
156-
OutputLine.from_csv(
157-
"'missing-docstring', 1, 2, 'obj', 'msg', 'func', 'message', 'conf', 'too_long'",
158-
True,
159-
)
160-
161-
162-
@pytest.mark.parametrize(
163-
"confidence,expected_confidence", [[None, "UNDEFINED"], ["INFERENCE", "INFERENCE"]]
164-
)
165-
def test_output_line_from_csv_deprecated(
166-
confidence: str | None, expected_confidence: str
167-
) -> None:
168-
"""Test that the OutputLine NamedTuple is instantiated correctly with from_csv.
169-
Test OutputLine's of length 5 or 6.
170-
"""
171-
if confidence:
172-
proper_csv = [
173-
"missing-docstring",
174-
"1",
175-
"2",
176-
"obj",
177-
"msg",
178-
confidence,
179-
]
180-
else:
181-
proper_csv = ["missing-docstring", "1", "2", "obj", "msg"]
182-
with pytest.warns(DeprecationWarning) as records:
183-
output_line = OutputLine.from_csv(proper_csv, True)
184-
assert len(records) == 1
185-
186-
expected_column = 2 if PY38_PLUS else 0
187-
assert output_line == OutputLine(
188-
symbol="missing-docstring",
189-
lineno=1,
190-
column=expected_column,
191-
end_lineno=None,
192-
end_column=None,
193-
object="obj",
194-
msg="msg",
195-
confidence=expected_confidence,
196-
)
197-
198-
199136
def test_output_line_from_csv() -> None:
200137
"""Test that the OutputLine NamedTuple is instantiated correctly with from_csv.
201138
Test OutputLine of length 8.
202139
"""
203-
proper_csv = [
204-
"missing-docstring",
205-
"1",
206-
"2",
207-
"1",
208-
"None",
209-
"obj",
210-
"msg",
211-
"HIGH",
212-
]
140+
proper_csv = ["missing-docstring", "1", "2", "1", "None", "obj", "msg", "HIGH"]
213141
expected_column = 2 if PY38_PLUS else 0
214142

215143
output_line = OutputLine.from_csv(proper_csv)

0 commit comments

Comments
 (0)