Skip to content

Commit d4348fa

Browse files
committed
Document who to turn on deprecation warnings
1 parent 068d853 commit d4348fa

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

docs/usage.rst

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ creating a version:
4242

4343
Module level functions are marked as *deprecated* in version 2.9.2 now.
4444
These functions will be removed in semver 3.
45-
For details, see section :ref:`sec_replace_deprecated_functions`.
45+
For details, see the sections :ref:`sec_replace_deprecated_functions` and
46+
:ref:`sec_display_deprecation_warnings`.
4647

4748

4849
A version can be created in different ways:
@@ -475,3 +476,39 @@ them with code which is compatible for future versions:
475476
>>> s2 = str(semver.VersionInfo.parse('1.2.3').replace(major=2, patch=10))
476477
>>> s1 == s2
477478
True
479+
480+
481+
.. _sec_display_deprecation_warnings:
482+
483+
Displaying Deprecation Warnings
484+
-------------------------------
485+
486+
By default, deprecation warnings are `ignored in Python <https://docs.python.org/3/library/warnings.html#warning-categories>`_.
487+
This also affects semver's own warnings.
488+
489+
It is recommended that you turn on deprecation warnings in your scripts. Use one of
490+
the following methods:
491+
492+
* Use the option `-Wd <https://docs.python.org/3/using/cmdline.html#cmdoption-w>`_
493+
to enable default warnings:
494+
495+
* Directly running the Python command::
496+
497+
$ python3 -Wd scriptname.py
498+
499+
* Add the option in the shebang line (something like ``#!/usr/bin/python3``)
500+
after the command::
501+
502+
#!/usr/bin/python3 -Wd
503+
504+
* In your own scripts add a filter to ensure that *all* warnings are displayed:
505+
506+
.. code-block:: python
507+
508+
import warnings
509+
warnings.simplefilter("default")
510+
# Call your semver code
511+
512+
For further details, see the section
513+
`Overriding the default filter <https://docs.python.org/3/library/warnings.html#overriding-the-default-filter>`_
514+
of the Python documentation.

0 commit comments

Comments
 (0)