-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
gh-106137: Add SoftDeprecationWarning category #106142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
a01636f
to
b6dc14a
Compare
I mark this PR as a draft until python/peps#3182 is merged. |
I will create a separated PR to add |
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
1e0e98d
Compare
* 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.
1e0e98d
to
2a2370e
Compare
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/