summaryrefslogtreecommitdiffstats
path: root/Lib/warnings.py
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2022-04-05 19:05:48 (GMT)
committerGitHub <noreply@github.com>2022-04-05 19:05:48 (GMT)
commitc1d93b6411f975d67e43942f1a2745a22983c18c (patch)
treecccdd369da191fa03268967013d60369ab48fcdf /Lib/warnings.py
parent944f09adfcc59f54432ac2947cf95f3465d90e1e (diff)
downloadcpython-c1d93b6411f975d67e43942f1a2745a22983c18c.zip
cpython-c1d93b6411f975d67e43942f1a2745a22983c18c.tar.gz
cpython-c1d93b6411f975d67e43942f1a2745a22983c18c.tar.bz2
bpo-47061: deprecate the `aifc` module (GH-32134)
Co-authored-by: Christian Heimes <christian@python.org>
Diffstat (limited to 'Lib/warnings.py')
-rw-r--r--Lib/warnings.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/warnings.py b/Lib/warnings.py
index 691ccdd..887ca6e 100644
--- a/Lib/warnings.py
+++ b/Lib/warnings.py
@@ -483,6 +483,27 @@ class catch_warnings(object):
self._module._showwarnmsg_impl = self._showwarnmsg_impl
+_DEPRECATED_MSG = "{name!r} is deprecated and slated for removal in Python {remove}"
+
+def _deprecated(name, message=_DEPRECATED_MSG, *, remove, _version=sys.version_info):
+ """Warn that *name* is deprecated or should be removed.
+
+ RuntimeError is raised if *remove* specifies a major/minor tuple older than
+ the current Python version or the same version but past the alpha.
+
+ The *message* argument is formatted with *name* and *remove* as a Python
+ version (e.g. "3.11").
+
+ """
+ remove_formatted = f"{remove[0]}.{remove[1]}"
+ if (_version[:2] > remove) or (_version[:2] == remove and _version[3] != "alpha"):
+ msg = f"{name!r} was slated for removal after Python {remove_formatted} alpha"
+ raise RuntimeError(msg)
+ else:
+ msg = message.format(name=name, remove=remove_formatted)
+ warn(msg, DeprecationWarning, stacklevel=3)
+
+
# Private utility function called by _PyErr_WarnUnawaitedCoroutine
def _warn_unawaited_coroutine(coro):
msg_lines = [