{{ message }}
gh-106137: Add SoftDeprecationWarning category - #106142
Closed
vstinner wants to merge 3 commits into
Closed
Conversation
vstinner
force-pushed
the
soft_deprecation
branch
from
June 27, 2023 14:22
a01636f to
b6dc14a
Compare
vstinner
marked this pull request as draft
June 27, 2023 14:22
Member
Author
Member
Author
|
I will create a separated PR to add |
Member
Author
|
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)
|
Member
Author
|
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 |
vstinner
force-pushed
the
soft_deprecation
branch
3 times, most recently
from
June 28, 2023 01:25
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.
vstinner
force-pushed
the
soft_deprecation
branch
from
June 28, 2023 01:54
1e0e98d to
2a2370e
Compare
Member
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

📚 Documentation preview 📚: https://cpython-previews--106142.org.readthedocs.build/