Skip to content

Commit 04d5bc0

Browse files
committed
Closes #13235: Added deprecation for warn() methods and function in logging.
1 parent ac65d96 commit 04d5bc0

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

Doc/library/logging.rst

+9-2
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ instantiated directly, but always through the module-level function
189189
Logs a message with level :const:`WARNING` on this logger. The arguments are
190190
interpreted as for :meth:`debug`.
191191

192+
.. note:: There is an obsolete method `warn()` which is functionally
193+
identical to `warning()`. As `warn()` is deprecated, please do not use
194+
it - use `warning()` instead.
192195

193196
.. method:: Logger.error(msg, *args, **kwargs)
194197

@@ -880,8 +883,12 @@ functions.
880883

881884
.. function:: warning(msg, *args, **kwargs)
882885

883-
Logs a message with level :const:`WARNING` on the root logger. The arguments are
884-
interpreted as for :func:`debug`.
886+
Logs a message with level :const:`WARNING` on the root logger. The arguments
887+
are interpreted as for :func:`debug`.
888+
889+
.. note:: There is an obsolete function `warn()` which is functionally
890+
identical to `warning()`. As `warn()` is deprecated, please do not use
891+
it - use `warning()` instead.
885892

886893

887894
.. function:: error(msg, *args, **kwargs)

Lib/logging/__init__.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -1243,7 +1243,10 @@ def warning(self, msg, *args, **kwargs):
12431243
if self.isEnabledFor(WARNING):
12441244
self._log(WARNING, msg, args, **kwargs)
12451245

1246-
warn = warning
1246+
def warn(self, msg, *args, **kwargs):
1247+
warnings.warn("The 'warn' method is deprecated, "
1248+
"use 'warning' instead", PendingDeprecationWarning, 2)
1249+
self.warning(msg, *args, **kwargs)
12471250

12481251
def error(self, msg, *args, **kwargs):
12491252
"""
@@ -1556,7 +1559,10 @@ def warning(self, msg, *args, **kwargs):
15561559
"""
15571560
self.log(WARNING, msg, *args, **kwargs)
15581561

1559-
warn = warning
1562+
def warn(self, msg, *args, **kwargs):
1563+
warnings.warn("The 'warn' method is deprecated, "
1564+
"use 'warning' instead", PendingDeprecationWarning, 2)
1565+
self.warning(msg, *args, **kwargs)
15601566

15611567
def error(self, msg, *args, **kwargs):
15621568
"""
@@ -1766,7 +1772,10 @@ def warning(msg, *args, **kwargs):
17661772
basicConfig()
17671773
root.warning(msg, *args, **kwargs)
17681774

1769-
warn = warning
1775+
def warn(msg, *args, **kwargs):
1776+
warnings.warn("The 'warn' function is deprecated, "
1777+
"use 'warning' instead", PendingDeprecationWarning, 2)
1778+
warning(msg, *args, **kwargs)
17701779

17711780
def info(msg, *args, **kwargs):
17721781
"""

Misc/NEWS

+2
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,8 @@ Core and Builtins
326326
Library
327327
-------
328328

329+
- Issue #13235: Added PendingDeprecationWarning to warn() method and function.
330+
329331
- Issue #9168: now smtpd is able to bind privileged port.
330332

331333
- Issue #12529: fix cgi.parse_header issue on strings with double-quotes and

0 commit comments

Comments
 (0)