diff options
author | Victor Stinner <vstinner@python.org> | 2024-08-09 13:13:24 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-09 13:13:24 (GMT) |
commit | d3239976a8e66ae3e2f4314a6889d79cdc9a9625 (patch) | |
tree | ddae5880d9b863f9b587c09816591bbe4529c5a9 /Lib | |
parent | b4a316087c32d83e375087fd35fc511bc430ee8b (diff) | |
download | cpython-d3239976a8e66ae3e2f4314a6889d79cdc9a9625.zip cpython-d3239976a8e66ae3e2f4314a6889d79cdc9a9625.tar.gz cpython-d3239976a8e66ae3e2f4314a6889d79cdc9a9625.tar.bz2 |
gh-105376: Restore deprecated logging warn() method (#122775)
This reverts commit dcc028d92428bd57358a5028ada2a53fc79fc365 and
commit 6c54e5d72166d012b52155cbf13af9e533290e06.
Keep the deprecated logging warn() method in Python 3.13.
Co-authored-by: Gregory P. Smith <greg@krypto.org>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/logging/__init__.py | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index 3f41442..aa9b79d 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -37,7 +37,7 @@ __all__ = ['BASIC_FORMAT', 'BufferingFormatter', 'CRITICAL', 'DEBUG', 'ERROR', 'captureWarnings', 'critical', 'debug', 'disable', 'error', 'exception', 'fatal', 'getLevelName', 'getLogger', 'getLoggerClass', 'info', 'log', 'makeLogRecord', 'setLoggerClass', 'shutdown', - 'warning', 'getLogRecordFactory', 'setLogRecordFactory', + 'warn', 'warning', 'getLogRecordFactory', 'setLogRecordFactory', 'lastResort', 'raiseExceptions', 'getLevelNamesMapping', 'getHandlerByName', 'getHandlerNames'] @@ -1530,6 +1530,11 @@ class Logger(Filterer): if self.isEnabledFor(WARNING): self._log(WARNING, msg, args, **kwargs) + def warn(self, msg, *args, **kwargs): + warnings.warn("The 'warn' method is deprecated, " + "use 'warning' instead", DeprecationWarning, 2) + self.warning(msg, *args, **kwargs) + def error(self, msg, *args, **kwargs): """ Log 'msg % args' with severity 'ERROR'. @@ -1906,6 +1911,11 @@ class LoggerAdapter(object): """ self.log(WARNING, msg, *args, **kwargs) + def warn(self, msg, *args, **kwargs): + warnings.warn("The 'warn' method is deprecated, " + "use 'warning' instead", DeprecationWarning, 2) + self.warning(msg, *args, **kwargs) + def error(self, msg, *args, **kwargs): """ Delegate an error call to the underlying logger. @@ -2169,6 +2179,11 @@ def warning(msg, *args, **kwargs): basicConfig() root.warning(msg, *args, **kwargs) +def warn(msg, *args, **kwargs): + warnings.warn("The 'warn' function is deprecated, " + "use 'warning' instead", DeprecationWarning, 2) + warning(msg, *args, **kwargs) + def info(msg, *args, **kwargs): """ Log a message with severity 'INFO' on the root logger. If the logger has |