What?
PEP 702 added the warnings.deprecated
decorator. This covers whole functions and classes, but there are other types of deprecation as well. For example at matplotlib we maintain a number of additional decorators such as
delete_parameter
- prepare to delete a no-longer needed parameterrename_parameter
- prepare to change the name of a parametermake_keyword_only
- prepare for inserting the kw-only marker*
in signaturesdeprecate_privatize_attribute
- to make a formerly public attribute private
I propose to add such functionality to the stdlib, either in warnings
or in a separate module like deprecation
(name t.b.d.)
Why is this useful?
API changes are sometimes required, either to correct previous design flaws or to adapt for new needs. To prevent breaking user code, such changes need to be announced via deprecations, ideally with a runtime warning when the deprecated feature is used.
While API stability is extremely valuable, structures that live for decades must be able to evolve. Authors should decide on changes solely based on user impact (gain vs cost of change). If they decide for a change, they should have tooling that makes the change easy.
Why is this a good fit for the standard library?
- Such deprecation helpers are not trivial to get right. Hence, users should not have to write them from scratch, but should be able to rely on a central implentation.
- There are a number of packages related to deprecation on PyPI. However, there does not seem to be a standard. None of them is widely used, some seem inactive, and they all have limited features, mostly implementing variants of
warnings.deprecated
but not the above mentioned use cases. Packages with a reasonably large user base are in most need for systematic deprecations, but OTOH these are cautious with adding dependencies. It may be hard to justiy an additional dependency to more easily handle deprecations. - The scope of the functions/decorators is quite clear. Once written, I don’t expect that the code will need to be altered much. Thus, maintainance burden is low.
- Like with PEP 702, static checkers could pick up the above cases as well. It’s much more likely they do that for a standard implementation in the stdlib compared to the same feature in a random PyPI package.
- While cpython is rightfully extra cautious with deprecations, there may be cases that such functionality could be used within cpython itself.