11---
22myst :
33 html_meta :
4- " description " : " A guide how to do deprecations, including Python, ZCML and templates in Plone ."
5- " property=og:description " : " A guide how to do deprecations, including Python, ZCML and templates in Plone ."
6- " property=og:title " : " Deprecation "
7- " keywords " : " deprecation, zcml, template, jbot"
4+ " description " : " How to implement deprecations in Plone , including Python, ZCML and templates."
5+ " property=og:description " : " How to implement deprecations in Plone , including Python, ZCML and templates."
6+ " property=og:title " : " Implement deprecations "
7+ " keywords " : " deprecation, zcml, template, jbot, Plone, Python "
88---
99
10- (backend-deprecation-label)=
11- # Deprecation
10+ (developer-deprecation-label)=
1211
13- ## Introduction
12+ # Implement deprecations
1413
15- This document describes rationales, configuration and best practices of deprecations in Plone, Zope and Python.
16- It is meant as a styleguide on how to apply deprecations in Plone core packages.
17- It also has a value as a general overview on how to deprecate in Python.
14+ This chapter describes how to enable deprecation warnings and best practices for implementing deprecations in Plone, Zope, and Python.
1815
16+ ``` {seealso}
17+ For background on deprecation philosophy and use cases, see {doc}`/conceptual-guides/deprecation`.
18+ ```
1919
20- ### Why Deprecation
21-
22- At some point we:
23-
24- - need to get rid of old code,
25- - want to unify API style (consistent API),
26- - fix typos in namings,
27- - move code or templates around (inside package or to another package).
28-
29- While refactoring code, moving modules, functions, classes and methods is often needed.
30- To not break third party code imports from the old place or usage of old functions/ methods must work for while.
31- Deprecated methods are usually removed with the next major release of Plone.
32-
33- Following the [ semantic versioning guideline] ( https://semver.org ) is recommended.
34-
35- ### Help Programmers, No annoyance
36-
37- The developers should use code deprecations to support the consumers of the code.
38- From their point of view, Plone core code is an API to them.
39- Any change is annoying to them anyway, but they feel better if deprecation warnings are telling them what to do.
40-
41- Deprecations must always log at level * warning* and have to answers the question:
42-
43- ** "Why is the code gone from the old place? What to do instead?"**
44-
45- A short message is enough., i.e.:
46-
47- - "Replaced by new API xyz, found at abc.cde".,
48- - "Moved to xyz, because of abc.",
49- - "Name had a typo, new name is "xyz".
50-
51- All logging has to be done once, i.e. on first usage or first import.
52- It must not flood the logs.
53-
54- ### Use Cases
55-
56- Renaming
57-
58- : We may want to rename classes, methods, functions or global or class variables in order to get a more consistent API or because of a typo, etc.
59- We never just rename, we always provide a deprecated version logging a verbose deprecation warning with information where to
60- import from in future.
61-
62- Moving a module, class, function, etc to another place
63-
64- : For some reason, i.e. merging packages, consistent API or resolving cirular import problems, we need to move code around.
65- When imported from the old place it logs a verbose deprecation warning with information where to import from in future.
66-
67- Deprecation of a whole package
68-
69- : A whole [ package] ( https://docs.python.org/3/tutorial/modules.html#packages )
70-
71- - all imports still working, logging deprecation warnings on first import
72- - ZCML still exists, but is empty (or includes the zcml from the new place if theres no auto import (i.e. for meta.zcml).
73-
74- Deprecation of a whole released/ installable package.
75-
76- : We will provide a last major release with no 'real' code, only backward compatible (bbb) imports of public API are provided.
77- This will be done the way described above for a whole package.
78- The README clearly states why it was moved and where to find the code now.
79-
80- Deprecation of a GenericSetup profile
81-
82- : They may got renamed for consistency or are superfluos after an update.
83- Code does not need to break to support this.
8420
85- ## Enable Deprecation Warnings
21+ ## Enable deprecation warnings
8622
8723### Zope
8824
@@ -158,9 +94,10 @@ the call looks like so:
15894./bin/python -W module ./bin/test
15995```
16096
161- ## Deprecation Best Practice
16297
163- ### Vanilla Deprecation Messages
98+ ## Deprecation best practice
99+
100+ ### Vanilla deprecation messages
164101
165102Python offers a built-in ` DeprecationWarning ` which can be issued using standard libraries ` warnings ` module.
166103
@@ -173,7 +110,7 @@ import warnings
173110warnings.warn(' deprecated' , DeprecationWarning )
174111```
175112
176- ### Moving Whole Modules
113+ ### Moving whole modules
177114
178115Given a package ` old.pkg ` with a module ` foo.py ` need to be moved to a package ` new.pkg ` as ` bar.py ` .
179116
@@ -192,7 +129,7 @@ Now you can still import the namespace from `bar` at the old place, but get a de
192129> DeprecationWarning: old.pkg.foo has moved to new.pkg.bar.
193130> Import of old.pkg.foo will become unsupported in Version 2.0
194131
195- ### Moving Whole Packages
132+ ### Moving whole packages
196133
197134This is the same as moving a module, just create for each module a file.
198135
0 commit comments