Uh oh!
There was an error while loading. Please reload this page.
gh-106137: Add SoftDeprecationWarning category - #106142
Conversation
vstinner
commented
Jun 27, 2023
I mark this PR as a draft until python/peps#3182 is merged. |
vstinner
commented
Jun 27, 2023
I will create a separated PR to add |
vstinner
commented
Jun 27, 2023
You can test this PR by soft deprecating the optparse module with this patch: diff --git a/Lib/optparse.py b/Lib/optparse.py
index 1c450c6fcb..ff1e24e295 100644
--- a/Lib/optparse.py+++ b/Lib/optparse.py@@ -76,6 +76,10 @@
import sys, os
import textwrap
+import warnings+warnings._soft_deprecated("the optparse module is soft deprecated: "+ "consider using the argparse module instead")+
def _repr(self):
return "<%s at 0x%x: %s>" % (self.__class__.__name__, id(self), self)
|
Examples with Python built in release mode. SoftDeprecationWarning is ignored by default: Example with soft deprecated optparse module (see the patch above), the warning is ignored because it's not event emitted: In the Python Development Mode, the warning is emitted and displayed: Ignore the soft deprecation warning in the Python Development Mode with |
ca9ff20 to
1e0e98dCompare* Add SoftDeprecationWarning warning category. * Add default warnings filters for SoftDeprecationWarning: ignore SoftDeprecationWarning by default, except in the __main__ module (similar to PEP 565). * Add warnings._soft_deprecated(): only emit SoftDeprecationWarning in Python Development Mode and if Python is built in debug mode. * Add PyExc_SoftDeprecationWarning to the limited C API.
vstinner
commented
Jun 30, 2023
The idea of issuing a warning for soft deprecations is not liked, so I abandon my idea: https://discuss.python.org/t/formalize-the-concept-of-soft-deprecation-dont-schedule-removal-in-pep-387-backwards-compatibility-policy/27957 |
📚 Documentation preview 📚: https://cpython-previews--106142.org.readthedocs.build/