Skip to content

Commit 1f52ae0

Browse files
TomNicholasandersy005mathause
authored
Explained what a deprecation cycle is (#5289)
Co-authored-by: Anderson Banihirwe <[email protected]> Co-authored-by: Mathias Hauser <[email protected]>
1 parent 1a7b285 commit 1f52ae0

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

doc/contributing.rst

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,10 +379,34 @@ with ``git commit --no-verify``.
379379
Backwards Compatibility
380380
~~~~~~~~~~~~~~~~~~~~~~~
381381

382-
Please try to maintain backward compatibility. *xarray* has growing number of users with
382+
Please try to maintain backwards compatibility. *xarray* has a growing number of users with
383383
lots of existing code, so don't break it if at all possible. If you think breakage is
384-
required, clearly state why as part of the pull request. Also, be careful when changing
385-
method signatures and add deprecation warnings where needed.
384+
required, clearly state why as part of the pull request.
385+
386+
Be especially careful when changing function and method signatures, because any change
387+
may require a deprecation warning. For example, if your pull request means that the
388+
argument ``old_arg`` to ``func`` is no longer valid, instead of simply raising an error if
389+
a user passes ``old_arg``, we would instead catch it:
390+
391+
.. code-block:: python
392+
393+
def func(new_arg, old_arg=None):
394+
if old_arg is not None:
395+
from warnings import warn
396+
397+
warn(
398+
"`old_arg` has been deprecated, and in the future will raise an error."
399+
"Please use `new_arg` from now on.",
400+
DeprecationWarning,
401+
)
402+
403+
# Still do what the user intended here
404+
405+
This temporary check would then be removed in a subsequent version of xarray.
406+
This process of first warning users before actually breaking their code is known as a
407+
"deprecation cycle", and makes changes significantly easier to handle both for users
408+
of xarray, and for developers of other libraries that depend on xarray.
409+
386410

387411
.. _contributing.ci:
388412

doc/whats-new.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ Bug fixes
4040
Documentation
4141
~~~~~~~~~~~~~
4242

43+
- Explanation of deprecation cycles and how to implement them added to contributors
44+
guide. (:pull:`5289`)
45+
By `Tom Nicholas <https://github.com/TomNicholas>`_.
46+
4347

4448
Internal Changes
4549
~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)