Skip to content

Commit 95a82dc

Browse files
Add explicit 'stack_level' keyword in Deprecation/User warnings
1 parent d4a8b02 commit 95a82dc

File tree

8 files changed

+16
-2
lines changed

8 files changed

+16
-2
lines changed

pylint/checkers/similar.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,12 +848,14 @@ def process_module(self, node: nodes.Module) -> None:
848848
stream must implement the readlines method
849849
"""
850850
if self.linter.current_name is None:
851+
# TODO: 3.0 Fix current_name
851852
warnings.warn(
852853
(
853854
"In pylint 3.0 the current_name attribute of the linter object should be a string. "
854855
"If unknown it should be initialized as an empty string."
855856
),
856857
DeprecationWarning,
858+
stacklevel=2,
857859
)
858860
with node.stream() as stream:
859861
self.append_stream(self.linter.current_name, stream, node.file_encoding)

pylint/config/deprecation_actions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,5 @@ def __call__(
104104
f"{self.option_strings[0]} has been deprecated. Please look into "
105105
f"using any of the following options: {', '.join(self.new_names)}.",
106106
DeprecationWarning,
107+
stacklevel=2,
107108
)

pylint/lint/caching.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def load_results(
4545
"You're using an old pylint cache with invalid data following "
4646
f"an upgrade, please delete '{data_file}'.",
4747
UserWarning,
48+
stacklevel=2,
4849
)
4950
raise TypeError
5051
return data

pylint/lint/run.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ def __init__(
175175
warnings.warn(
176176
"NOTE: The 'pylint-config' command is experimental and usage can change",
177177
UserWarning,
178+
stacklevel=2,
178179
)
179180
code = _handle_pylint_config_commands(linter)
180181
if exit:
@@ -216,9 +217,11 @@ def __init__(
216217
score_value = linter.generate_reports()
217218

218219
if do_exit is not UNUSED_PARAM_SENTINEL:
220+
# TODO: 3.0
219221
warnings.warn(
220222
"do_exit is deprecated and it is going to be removed in a future version.",
221223
DeprecationWarning,
224+
stacklevel=2,
222225
)
223226
exit = do_exit
224227

pylint/message/message_definition.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,15 @@ def may_be_emitted(
8080
"""Return True if message may be emitted using the configured py_version."""
8181
if py_version is None:
8282
py_version = sys.version_info
83+
# TODO: 3.0
8384
warnings.warn(
8485
"'py_version' will be a required parameter of "
8586
"'MessageDefinition.may_be_emitted' in pylint 3.0. The most likely "
8687
"solution is to use 'linter.config.py_version' if you need to keep "
8788
"using this function, or to use 'MessageDefinition.is_message_enabled'"
8889
" instead.",
8990
DeprecationWarning,
91+
stacklevel=2,
9092
)
9193
if self.minversion is not None and self.minversion > py_version:
9294
return False

pylint/reporters/text.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ def on_set_current_module(self, module: str, filepath: str | None) -> None:
137137
if argument[0] not in MESSAGE_FIELDS:
138138
warnings.warn(
139139
f"Don't recognize the argument '{argument[0]}' in the --msg-template. "
140-
"Are you sure it is supported on the current version of pylint?"
140+
"Are you sure it is supported on the current version of pylint?",
141+
stacklevel=2,
141142
)
142143
template = re.sub(r"\{" + argument[0] + r"(:.*?)?\}", "", template)
143144
self._fixed_template = template

pylint/testutils/_primer/primer_run_command.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ def _lint_package(
9696
if fatal_msgs:
9797
warnings.warn(
9898
f"Encountered fatal errors while priming {package_name} !\n"
99-
f"{self._print_msgs(fatal_msgs)}\n\n"
99+
f"{self._print_msgs(fatal_msgs)}\n\n",
100+
stacklevel=2,
100101
)
101102
return messages, fatal_msgs

pylint/testutils/output_line.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ def from_csv(
9494
try:
9595
column = cls._get_column(row[2])
9696
if len(row) == 5:
97+
# TODO: 3.0
9798
warnings.warn(
9899
"In pylint 3.0 functional tests expected output should always include the "
99100
"expected confidence level, expected end_line and expected end_column. "
@@ -112,6 +113,7 @@ def from_csv(
112113
UNDEFINED.name,
113114
)
114115
if len(row) == 6:
116+
# TODO: 3.0
115117
warnings.warn(
116118
"In pylint 3.0 functional tests expected output should always include the "
117119
"expected end_line and expected end_column. An OutputLine should thus have "
@@ -142,6 +144,7 @@ def from_csv(
142144
f"CONFIDENCE' but we got '{':'.join(row)}'. Try updating the expected"
143145
f" output with:\npython tests/test_functional.py {UPDATE_OPTION}",
144146
UserWarning,
147+
stacklevel=2,
145148
)
146149
return cls("", 0, 0, None, None, "", "", "")
147150

0 commit comments

Comments
 (0)