summaryrefslogtreecommitdiff
path: root/pylint/config
diff options
context:
space:
mode:
authorYilei "Dolee" Yang <yileiyang@google.com>2022-09-15 03:36:41 -0700
committerGitHub <noreply@github.com>2022-09-15 12:36:41 +0200
commita57edea63fa7a1edfcb63074f9e2a373ebabb7cd (patch)
treed7a18bd93116036518ddeed2a2253e72a2a7f5fc /pylint/config
parent27925396c85ffc443243589a0c03e430de9d7fa5 (diff)
downloadpylint-git-a57edea63fa7a1edfcb63074f9e2a373ebabb7cd.tar.gz
Use stacklevel=2 in warnings.warn calls to DeprecationWarning where makes sense. (#7465)
Co-authored-by: Daniƫl van Noord <13665637+DanielNoord@users.noreply.github.com> Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
Diffstat (limited to 'pylint/config')
-rw-r--r--pylint/config/__init__.py2
-rw-r--r--pylint/config/arguments_manager.py19
-rw-r--r--pylint/config/arguments_provider.py11
-rw-r--r--pylint/config/configuration_mixin.py1
-rw-r--r--pylint/config/find_default_config_files.py1
-rw-r--r--pylint/config/option.py1
-rw-r--r--pylint/config/option_manager_mixin.py1
-rw-r--r--pylint/config/option_parser.py1
-rw-r--r--pylint/config/options_provider_mixin.py1
9 files changed, 38 insertions, 0 deletions
diff --git a/pylint/config/__init__.py b/pylint/config/__init__.py
index 9a0d71f40..5f90bbae0 100644
--- a/pylint/config/__init__.py
+++ b/pylint/config/__init__.py
@@ -48,6 +48,7 @@ def load_results(base: str) -> LinterStats | None:
"'pylint.config.load_results' is deprecated, please use "
"'pylint.lint.load_results' instead. This will be removed in 3.0.",
DeprecationWarning,
+ stacklevel=2,
)
return _real_load_results(base, PYLINT_HOME)
@@ -61,5 +62,6 @@ def save_results(results: LinterStats, base: str) -> None:
"'pylint.config.save_results' is deprecated, please use "
"'pylint.lint.save_results' instead. This will be removed in 3.0.",
DeprecationWarning,
+ stacklevel=2,
)
return _real_save_results(results, base, PYLINT_HOME)
diff --git a/pylint/config/arguments_manager.py b/pylint/config/arguments_manager.py
index 2643e522f..1d1d683fe 100644
--- a/pylint/config/arguments_manager.py
+++ b/pylint/config/arguments_manager.py
@@ -125,6 +125,7 @@ class _ArgumentsManager:
warnings.warn(
"options_providers has been deprecated. It will be removed in pylint 3.0.",
DeprecationWarning,
+ stacklevel=2,
)
return self._options_providers
@@ -133,6 +134,7 @@ class _ArgumentsManager:
warnings.warn(
"Setting options_providers has been deprecated. It will be removed in pylint 3.0.",
DeprecationWarning,
+ stacklevel=2,
)
self._options_providers = value
@@ -282,6 +284,7 @@ class _ArgumentsManager:
"reset_parsers has been deprecated. Parsers should be instantiated "
"once during initialization and do not need to be reset.",
DeprecationWarning,
+ stacklevel=2,
)
# configuration file parser
self.cfgfile_parser = configparser.ConfigParser(
@@ -301,6 +304,7 @@ class _ArgumentsManager:
"arguments providers should be registered by initializing ArgumentsProvider. "
"This automatically registers the provider on the ArgumentsManager.",
DeprecationWarning,
+ stacklevel=2,
)
self.options_providers.append(provider)
non_group_spec_options = [
@@ -345,6 +349,7 @@ class _ArgumentsManager:
"registered by initializing ArgumentsProvider. "
"This automatically registers the group on the ArgumentsManager.",
DeprecationWarning,
+ stacklevel=2,
)
# add option group to the command line parser
if group_name in self._mygroups:
@@ -381,6 +386,7 @@ class _ArgumentsManager:
"add_optik_option has been deprecated. Options should be automatically "
"added by initializing an ArgumentsProvider.",
DeprecationWarning,
+ stacklevel=2,
)
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=DeprecationWarning)
@@ -399,6 +405,7 @@ class _ArgumentsManager:
"optik_option has been deprecated. Parsing of option dictionaries should be done "
"automatically by initializing an ArgumentsProvider.",
DeprecationWarning,
+ stacklevel=2,
)
optdict = copy.copy(optdict)
if "action" in optdict:
@@ -436,6 +443,7 @@ class _ArgumentsManager:
warnings.warn(
"generate_config has been deprecated. It will be removed in pylint 3.0.",
DeprecationWarning,
+ stacklevel=2,
)
options_by_section = {}
sections = []
@@ -495,6 +503,7 @@ class _ArgumentsManager:
"load_provider_defaults has been deprecated. Parsing of option defaults should be done "
"automatically by initializing an ArgumentsProvider.",
DeprecationWarning,
+ stacklevel=2,
)
for provider in self.options_providers:
with warnings.catch_warnings():
@@ -512,6 +521,7 @@ class _ArgumentsManager:
warnings.warn(
"read_config_file has been deprecated. It will be removed in pylint 3.0.",
DeprecationWarning,
+ stacklevel=2,
)
if not config_file:
if verbose:
@@ -583,6 +593,7 @@ class _ArgumentsManager:
warnings.warn(
"load_config_file has been deprecated. It will be removed in pylint 3.0.",
DeprecationWarning,
+ stacklevel=2,
)
parser = self.cfgfile_parser
for section in parser.sections():
@@ -597,6 +608,7 @@ class _ArgumentsManager:
warnings.warn(
"load_configuration has been deprecated. It will be removed in pylint 3.0.",
DeprecationWarning,
+ stacklevel=2,
)
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=DeprecationWarning)
@@ -608,6 +620,7 @@ class _ArgumentsManager:
warnings.warn(
"DEPRECATED: load_configuration_from_config has been deprecated. It will be removed in pylint 3.0.",
DeprecationWarning,
+ stacklevel=2,
)
for opt, opt_value in config.items():
opt = opt.replace("_", "-")
@@ -624,6 +637,7 @@ class _ArgumentsManager:
warnings.warn(
"load_command_line_configuration has been deprecated. It will be removed in pylint 3.0.",
DeprecationWarning,
+ stacklevel=2,
)
args = sys.argv[1:] if args is None else list(args)
(options, args) = self.cmdline_parser.parse_args(args=args)
@@ -643,6 +657,7 @@ class _ArgumentsManager:
"Supplying a 'level' argument to help() has been deprecated."
"You can call help() without any arguments.",
DeprecationWarning,
+ stacklevel=2,
)
return self._arg_parser.format_help()
@@ -654,6 +669,7 @@ class _ArgumentsManager:
warnings.warn(
"cb_set_provider_option has been deprecated. It will be removed in pylint 3.0.",
DeprecationWarning,
+ stacklevel=2,
)
if opt.startswith("--"):
# remove -- on long option
@@ -673,6 +689,7 @@ class _ArgumentsManager:
"global_set_option has been deprecated. You can use _arguments_manager.set_option "
"or linter.set_option to set options on the global configuration object.",
DeprecationWarning,
+ stacklevel=2,
)
self.set_option(opt, value)
@@ -776,12 +793,14 @@ class _ArgumentsManager:
"The 'action' argument has been deprecated. You can use set_option "
"without the 'action' or 'optdict' arguments.",
DeprecationWarning,
+ stacklevel=2,
)
if optdict != "default_value":
warnings.warn(
"The 'optdict' argument has been deprecated. You can use set_option "
"without the 'action' or 'optdict' arguments.",
DeprecationWarning,
+ stacklevel=2,
)
self.config = self._arg_parser.parse_known_args(
diff --git a/pylint/config/arguments_provider.py b/pylint/config/arguments_provider.py
index 6933324cc..ea229e1c3 100644
--- a/pylint/config/arguments_provider.py
+++ b/pylint/config/arguments_provider.py
@@ -24,6 +24,7 @@ class UnsupportedAction(Exception):
warnings.warn(
"UnsupportedAction has been deprecated and will be removed in pylint 3.0",
DeprecationWarning,
+ stacklevel=2,
)
super().__init__(*args)
@@ -55,6 +56,7 @@ class _ArgumentsProvider:
"The level attribute has been deprecated. It was used to display the checker in the help or not,"
" and everything is displayed in the help now. It will be removed in pylint 3.0.",
DeprecationWarning,
+ stacklevel=2,
)
return self._level
@@ -65,6 +67,7 @@ class _ArgumentsProvider:
"Setting the level attribute has been deprecated. It was used to display the checker in the help or not,"
" and everything is displayed in the help now. It will be removed in pylint 3.0.",
DeprecationWarning,
+ stacklevel=2,
)
self._level = value
@@ -75,6 +78,7 @@ class _ArgumentsProvider:
"The checker-specific config attribute has been deprecated. Please use "
"'linter.config' to access the global configuration object.",
DeprecationWarning,
+ stacklevel=2,
)
return self._arguments_manager.config
@@ -85,6 +89,7 @@ class _ArgumentsProvider:
"registered by initializing an ArgumentsProvider. "
"This automatically registers the group on the ArgumentsManager.",
DeprecationWarning,
+ stacklevel=2,
)
for opt, optdict in self.options:
action = optdict.get("action")
@@ -105,6 +110,7 @@ class _ArgumentsProvider:
"option_attrname has been deprecated. It will be removed "
"in a future release.",
DeprecationWarning,
+ stacklevel=2,
)
if optdict is None:
with warnings.catch_warnings():
@@ -118,6 +124,7 @@ class _ArgumentsProvider:
"option_value has been deprecated. It will be removed "
"in a future release.",
DeprecationWarning,
+ stacklevel=2,
)
return getattr(self._arguments_manager.config, opt.replace("-", "_"), None)
@@ -136,6 +143,7 @@ class _ArgumentsProvider:
"set_option has been deprecated. You can use _arguments_manager.set_option "
"or linter.set_option to set options on the global configuration object.",
DeprecationWarning,
+ stacklevel=2,
)
self._arguments_manager.set_option(optname, value)
@@ -148,6 +156,7 @@ class _ArgumentsProvider:
"get_option_def has been deprecated. It will be removed "
"in a future release.",
DeprecationWarning,
+ stacklevel=2,
)
assert self.options
for option in self.options:
@@ -174,6 +183,7 @@ class _ArgumentsProvider:
"options_by_section has been deprecated. It will be removed "
"in a future release.",
DeprecationWarning,
+ stacklevel=2,
)
sections: dict[str, list[tuple[str, OptionDict, Any]]] = {}
for optname, optdict in self.options:
@@ -195,6 +205,7 @@ class _ArgumentsProvider:
"options_and_values has been deprecated. It will be removed "
"in a future release.",
DeprecationWarning,
+ stacklevel=2,
)
if options is None:
options = self.options
diff --git a/pylint/config/configuration_mixin.py b/pylint/config/configuration_mixin.py
index cdf6ad4fc..7a06857c5 100644
--- a/pylint/config/configuration_mixin.py
+++ b/pylint/config/configuration_mixin.py
@@ -21,6 +21,7 @@ class ConfigurationMixIn(OptionsManagerMixIn, OptionsProviderMixIn): # type: ig
warnings.warn(
"ConfigurationMixIn has been deprecated and will be removed in pylint 3.0",
DeprecationWarning,
+ stacklevel=2,
)
if not args:
kwargs.setdefault("usage", "")
diff --git a/pylint/config/find_default_config_files.py b/pylint/config/find_default_config_files.py
index 314e70e11..43e682a58 100644
--- a/pylint/config/find_default_config_files.py
+++ b/pylint/config/find_default_config_files.py
@@ -122,6 +122,7 @@ def find_pylintrc() -> str | None:
"Use find_default_config_files if you want access to pylint's configuration file "
"finding logic.",
DeprecationWarning,
+ stacklevel=2,
)
for config_file in find_default_config_files():
if str(config_file).endswith("pylintrc"):
diff --git a/pylint/config/option.py b/pylint/config/option.py
index effd36f73..12412a2d4 100644
--- a/pylint/config/option.py
+++ b/pylint/config/option.py
@@ -190,6 +190,7 @@ class Option(optparse.Option):
warnings.warn(
"Option has been deprecated and will be removed in pylint 3.0",
DeprecationWarning,
+ stacklevel=2,
)
super().__init__(*opts, **attrs)
if hasattr(self, "hide") and self.hide: # type: ignore[attr-defined]
diff --git a/pylint/config/option_manager_mixin.py b/pylint/config/option_manager_mixin.py
index ef46a074f..c468f494f 100644
--- a/pylint/config/option_manager_mixin.py
+++ b/pylint/config/option_manager_mixin.py
@@ -77,6 +77,7 @@ class OptionsManagerMixIn:
warnings.warn(
"OptionsManagerMixIn has been deprecated and will be removed in pylint 3.0",
DeprecationWarning,
+ stacklevel=2,
)
self.reset_parsers(usage)
# list of registered options providers
diff --git a/pylint/config/option_parser.py b/pylint/config/option_parser.py
index 78984db34..c527c4f60 100644
--- a/pylint/config/option_parser.py
+++ b/pylint/config/option_parser.py
@@ -25,6 +25,7 @@ class OptionParser(optparse.OptionParser):
warnings.warn(
"OptionParser has been deprecated and will be removed in pylint 3.0",
DeprecationWarning,
+ stacklevel=2,
)
super().__init__(option_class=Option, *args, **kwargs)
diff --git a/pylint/config/options_provider_mixin.py b/pylint/config/options_provider_mixin.py
index ef85149a9..67f64ee0a 100644
--- a/pylint/config/options_provider_mixin.py
+++ b/pylint/config/options_provider_mixin.py
@@ -29,6 +29,7 @@ class OptionsProviderMixIn:
warnings.warn(
"OptionsProviderMixIn has been deprecated and will be removed in pylint 3.0",
DeprecationWarning,
+ stacklevel=2,
)
self.config = optparse.Values()
self.load_defaults()