# note: everything below needs Python 3.13 or newer. The bank runs
# Python 3.12, where this is not there yet.
import warnings
# *** before: ***
# the warning was raised by hand inside the body, the docstring repeated
# it in words, and neither a checker nor an editor knew anything about it
def old_style(text):
"""Deprecated, use new_style instead.TDQuote
warnings.warn("old_style is deprecated, use new_style",
DeprecationWarning, stacklevel=2)
return text.upper()
# *** in version 3.13: ***
from warnings import deprecated
@deprecated("use new_style instead")
def old_style_new(text):
return text.upper()
@deprecated("Shape is replaced by Figure")
class Shape:
pass
class Figure:
@deprecated("use area() instead")
def size(self):
return 0
def new_style(text):
return text.upper()
# the decorator does BOTH jobs at once: it raises a DeprecationWarning
# when the name is used, and marks it for checkers and editors, which
# strike the name through right at the call
with warnings.catch_warnings(record=True) as caught:
warnings.simplefilter("always")
print(old_style("a"), old_style_new("b"), new_style("c"))
Figure().size()
for entry in caught:
print(entry.category.__name__ + ":", entry.message)