From 91b353774deea30d362ad7d01adef41d39a4559d Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 7 Aug 2024 14:05:08 +0200 Subject: [PATCH 1/4] gh-105376: Restore deprecated logging warn() method This reverts commit dcc028d92428bd57358a5028ada2a53fc79fc365 and commit 6c54e5d72166d012b52155cbf13af9e533290e06. Keep the deprecated logging warn() method in Python 3.13. --- Doc/library/logging.rst | 17 ++++------------- Doc/whatsnew/3.13.rst | 10 ---------- Lib/logging/__init__.py | 17 ++++++++++++++++- ...24-08-07-14-12-19.gh-issue-105376.QbGPdE.rst | 3 +++ 4 files changed, 23 insertions(+), 24 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2024-08-07-14-12-19.gh-issue-105376.QbGPdE.rst diff --git a/Doc/library/logging.rst b/Doc/library/logging.rst index 4ba520c139ebce..204d7e423012d2 100644 --- a/Doc/library/logging.rst +++ b/Doc/library/logging.rst @@ -352,10 +352,6 @@ in a module, ``__name__`` is the module's name in the Python package namespace. .. versionchanged:: 3.8 The *stacklevel* parameter was added. - .. versionchanged:: 3.13 - Remove the undocumented ``warn()`` method which was an alias to the - :meth:`warning` method. - .. method:: Logger.info(msg, *args, **kwargs) @@ -368,6 +364,10 @@ in a module, ``__name__`` is the module's name in the Python package namespace. Logs a message with level :const:`WARNING` on this logger. The arguments are interpreted as for :meth:`debug`. + .. note:: There is an obsolete method ``warn`` which is functionally + identical to ``warning``. As ``warn`` is deprecated, please do not use + it - use ``warning`` instead. + .. method:: Logger.error(msg, *args, **kwargs) Logs a message with level :const:`ERROR` on this logger. The arguments are @@ -1124,11 +1124,6 @@ information into logging calls. For a usage example, see the section on Attribute :attr:`!manager` and method :meth:`!_log` were added, which delegate to the underlying logger and allow adapters to be nested. - .. versionchanged:: 3.13 - - Remove the undocumented :meth:`!warn`` method which was an alias to the - :meth:`!warning` method. - .. versionchanged:: 3.13 The *merge_extra* argument was added. @@ -1224,10 +1219,6 @@ functions. identical to ``warning``. As ``warn`` is deprecated, please do not use it - use ``warning`` instead. - .. versionchanged:: 3.13 - Remove the undocumented ``warn()`` function which was an alias to the - :func:`warning` function. - .. function:: error(msg, *args, **kwargs) diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index 5c57b5d7ebe2ff..aa06e92afc9a43 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -1397,16 +1397,6 @@ locale use ``locale.setlocale(locale.LC_ALL, "")`` instead. (Contributed by Victor Stinner in :gh:`104783`.) -logging -------- - -* :mod:`logging`: Remove undocumented and untested ``Logger.warn()`` and - ``LoggerAdapter.warn()`` methods and ``logging.warn()`` function. Deprecated - since Python 3.3, they were aliases to the :meth:`logging.Logger.warning` - method, :meth:`!logging.LoggerAdapter.warning` method and - :func:`logging.warning` function. - (Contributed by Victor Stinner in :gh:`105376`.) - pathlib ------- diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index 3f4144226b40ec..aa9b79d8cab4bb 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -37,7 +37,7 @@ '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 @@ def warning(self, msg, *args, **kwargs): 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 @@ def warning(self, msg, *args, **kwargs): """ 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 diff --git a/Misc/NEWS.d/next/Library/2024-08-07-14-12-19.gh-issue-105376.QbGPdE.rst b/Misc/NEWS.d/next/Library/2024-08-07-14-12-19.gh-issue-105376.QbGPdE.rst new file mode 100644 index 00000000000000..9756a14cbcf67e --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-08-07-14-12-19.gh-issue-105376.QbGPdE.rst @@ -0,0 +1,3 @@ +Restore the deprecated :mod:`logging` ``warn()`` method. It was removed in +Python 3.13 alpha 1. Keep the deprecated ``warn()`` method in Python 3.13. +Patch by Victor Stinner. From 716b9d1344322566482a9bf2a9eedb40e52474c3 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 7 Aug 2024 16:53:10 +0200 Subject: [PATCH 2/4] Mention the pending removal --- Doc/deprecations/pending-removal-in-future.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Doc/deprecations/pending-removal-in-future.rst b/Doc/deprecations/pending-removal-in-future.rst index 7f10d9a98257f9..8fcfb7846a4179 100644 --- a/Doc/deprecations/pending-removal-in-future.rst +++ b/Doc/deprecations/pending-removal-in-future.rst @@ -67,6 +67,9 @@ although there is currently no date scheduled for their removal. * ``EntryPoints`` tuple interface. * Implicit ``None`` on return values. +* :mod:`logging`: the ``warn()`` method is deprecated, use ``warning()`` + instead. + * :mod:`mailbox`: Use of StringIO input and text mode is deprecated, use BytesIO and binary mode instead. From 34f45f59de2e2b7ff9136003cfd8367058eb90bb Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Wed, 7 Aug 2024 11:14:30 -0700 Subject: [PATCH 3/4] Update Doc/deprecations/pending-removal-in-future.rst Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> --- Doc/deprecations/pending-removal-in-future.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/deprecations/pending-removal-in-future.rst b/Doc/deprecations/pending-removal-in-future.rst index 8fcfb7846a4179..ff6fd6a754e0b8 100644 --- a/Doc/deprecations/pending-removal-in-future.rst +++ b/Doc/deprecations/pending-removal-in-future.rst @@ -67,8 +67,8 @@ although there is currently no date scheduled for their removal. * ``EntryPoints`` tuple interface. * Implicit ``None`` on return values. -* :mod:`logging`: the ``warn()`` method is deprecated, use ``warning()`` - instead. +* :mod:`logging`: the :meth:`~logging.warn()` method has been deprecated + since Python 3.3, use :meth:`~logging.warning()` instead. * :mod:`mailbox`: Use of StringIO input and text mode is deprecated, use BytesIO and binary mode instead. From 3cc5db8623e1deb1df03849f6656f7e10b8b2e82 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Wed, 7 Aug 2024 22:20:50 +0300 Subject: [PATCH 4/4] Update Doc/deprecations/pending-removal-in-future.rst --- Doc/deprecations/pending-removal-in-future.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/deprecations/pending-removal-in-future.rst b/Doc/deprecations/pending-removal-in-future.rst index ff6fd6a754e0b8..6942b9d62cb8f2 100644 --- a/Doc/deprecations/pending-removal-in-future.rst +++ b/Doc/deprecations/pending-removal-in-future.rst @@ -67,7 +67,7 @@ although there is currently no date scheduled for their removal. * ``EntryPoints`` tuple interface. * Implicit ``None`` on return values. -* :mod:`logging`: the :meth:`~logging.warn()` method has been deprecated +* :mod:`logging`: the ``warn()`` method has been deprecated since Python 3.3, use :meth:`~logging.warning()` instead. * :mod:`mailbox`: Use of StringIO input and text mode is deprecated, use