From 38e4b1e8047affc76884def40f8a956d4f7797c3 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 26 Apr 2022 09:07:27 +0200 Subject: [PATCH 1/4] gh-68966: Deprecate the mailcap module --- Doc/library/mailcap.rst | 3 +++ Doc/whatsnew/3.11.rst | 5 +++++ Lib/mailcap.py | 6 ++++++ Lib/test/test_mailcap.py | 15 +++++++++++---- .../2022-04-26-09-09-07.gh-issue-68966.roapI2.rst | 3 +++ 5 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2022-04-26-09-09-07.gh-issue-68966.roapI2.rst diff --git a/Doc/library/mailcap.rst b/Doc/library/mailcap.rst index 7749b7dd45ef44..c88e056b3db52f 100644 --- a/Doc/library/mailcap.rst +++ b/Doc/library/mailcap.rst @@ -6,6 +6,9 @@ **Source code:** :source:`Lib/mailcap.py` +.. deprecated-removed:: 3.11 3.13 + See the :mod:`mimetypes` module for an alternative. + -------------- Mailcap files are used to configure how MIME-aware applications such as mail diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 8f0d3c7c7099a3..3e42560f1a0155 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -985,6 +985,11 @@ Deprecated be able to parse Python 3.10 or newer. See the :pep:`617` (New PEG parser for CPython). (Contributed by Victor Stinner in :issue:`40360`.) +* The :mod:`mailcap` module is now deprecated and will be removed in Python + 3.13. See :pep:`594` for the rationale and the :mod:`mimetypes` module for an + alternative. + (Contributed by Victor Stinner in :gh:`68966`.) + * Undocumented modules ``sre_compile``, ``sre_constants`` and ``sre_parse`` are now deprecated. (Contributed by Serhiy Storchaka in :issue:`47152`.) diff --git a/Lib/mailcap.py b/Lib/mailcap.py index ae416a8e9fb273..856b6a55475f38 100644 --- a/Lib/mailcap.py +++ b/Lib/mailcap.py @@ -6,6 +6,12 @@ __all__ = ["getcaps","findmatch"] +_DEPRECATION_MSG = ('The {name} module is deprecated and will be removed in ' + 'Python {remove}. See the mimetypes module for an ' + 'alternative.') +warnings._deprecated(__name__, _DEPRECATION_MSG, remove=(3, 13)) + + def lineno_sort_key(entry): # Sort in ascending order, with unspecified entries at the end if 'lineno' in entry: diff --git a/Lib/test/test_mailcap.py b/Lib/test/test_mailcap.py index ef9cad498a75c2..26ba4630ff248b 100644 --- a/Lib/test/test_mailcap.py +++ b/Lib/test/test_mailcap.py @@ -1,10 +1,17 @@ -import mailcap -import os import copy +import os +import sys import test.support -from test.support import os_helper import unittest -import sys +import warnings +from test.support import os_helper + + +with warnings.catch_warnings(): + # mailcap is deprecated + warnings.simplefilter('ignore', DeprecationWarning) + import mailcap + # Location of mailcap file MAILCAPFILE = test.support.findfile("mailcap.txt") diff --git a/Misc/NEWS.d/next/Library/2022-04-26-09-09-07.gh-issue-68966.roapI2.rst b/Misc/NEWS.d/next/Library/2022-04-26-09-09-07.gh-issue-68966.roapI2.rst new file mode 100644 index 00000000000000..5c9ffbf09f0059 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-04-26-09-09-07.gh-issue-68966.roapI2.rst @@ -0,0 +1,3 @@ +The :mod:`mailcap` module is now deprecated and will be removed in Python 3.13. +See :pep:`594` for the rationale and the :mod:`mimetypes` module for an +alternative. Patch by Victor Stinner. From d6b0e9a5ef09143a0efa7b9e79f1bfcff79538ba Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 26 Apr 2022 11:59:09 +0200 Subject: [PATCH 2/4] Addresse Hugo's review --- Doc/library/mailcap.rst | 5 +++-- Doc/library/netdata.rst | 1 - Doc/library/superseded.rst | 3 ++- Doc/whatsnew/3.11.rst | 9 +++------ 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/Doc/library/mailcap.rst b/Doc/library/mailcap.rst index c88e056b3db52f..90869d55c06963 100644 --- a/Doc/library/mailcap.rst +++ b/Doc/library/mailcap.rst @@ -6,8 +6,9 @@ **Source code:** :source:`Lib/mailcap.py` -.. deprecated-removed:: 3.11 3.13 - See the :mod:`mimetypes` module for an alternative. +.. deprecated:: 3.11 + The :mod:`mailcap` module is deprecated. See :pep:`594` for the rationale + and the :mod:`mimetypes` module for an alternative. -------------- diff --git a/Doc/library/netdata.rst b/Doc/library/netdata.rst index 8955e859ab634c..1541e2a5444590 100644 --- a/Doc/library/netdata.rst +++ b/Doc/library/netdata.rst @@ -13,7 +13,6 @@ on the internet. email.rst json.rst - mailcap.rst mailbox.rst mimetypes.rst base64.rst diff --git a/Doc/library/superseded.rst b/Doc/library/superseded.rst index e3f9b0d37fe10b..b38f16691f6ea9 100644 --- a/Doc/library/superseded.rst +++ b/Doc/library/superseded.rst @@ -20,9 +20,10 @@ backwards compatibility. They have been superseded by other modules. crypt.rst imghdr.rst imp.rst + mailcap.rst msilib.rst - nntplib.rst nis.rst + nntplib.rst optparse.rst ossaudiodev.rst pipes.rst diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 3e42560f1a0155..d57036d4d425c7 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -985,11 +985,6 @@ Deprecated be able to parse Python 3.10 or newer. See the :pep:`617` (New PEG parser for CPython). (Contributed by Victor Stinner in :issue:`40360`.) -* The :mod:`mailcap` module is now deprecated and will be removed in Python - 3.13. See :pep:`594` for the rationale and the :mod:`mimetypes` module for an - alternative. - (Contributed by Victor Stinner in :gh:`68966`.) - * Undocumented modules ``sre_compile``, ``sre_constants`` and ``sre_parse`` are now deprecated. (Contributed by Serhiy Storchaka in :issue:`47152`.) @@ -1066,6 +1061,7 @@ Deprecated * :mod:`chunk` * :mod:`crypt` * :mod:`imghdr` + * :mod:`mailcap` * :mod:`msilib` * :mod:`nis` * :mod:`nntplib` @@ -1075,7 +1071,8 @@ Deprecated * :mod:`spwd` * :mod:`sunau` - (Contributed by Brett Cannon in :issue:`47061`.) + (Contributed by Brett Cannon in :issue:`47061` and Victor Stinner in + :gh:`68966`.) Removed From e8668224e660db2334c4ad4c7199b8803349b2a8 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 26 Apr 2022 15:58:39 +0200 Subject: [PATCH 3/4] Add :deprecated: --- Doc/library/mailcap.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/Doc/library/mailcap.rst b/Doc/library/mailcap.rst index 90869d55c06963..416b181f45a772 100644 --- a/Doc/library/mailcap.rst +++ b/Doc/library/mailcap.rst @@ -3,6 +3,7 @@ .. module:: mailcap :synopsis: Mailcap file handling. + :deprecated: **Source code:** :source:`Lib/mailcap.py` From dc9db721f701c9e88385cc849aad9b66742b8050 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 26 Apr 2022 17:37:35 +0200 Subject: [PATCH 4/4] Use warnings_helper.import_deprecated() --- Lib/test/test_mailcap.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_mailcap.py b/Lib/test/test_mailcap.py index 26ba4630ff248b..97a8fac6e074ad 100644 --- a/Lib/test/test_mailcap.py +++ b/Lib/test/test_mailcap.py @@ -5,12 +5,10 @@ import unittest import warnings from test.support import os_helper +from test.support import warnings_helper -with warnings.catch_warnings(): - # mailcap is deprecated - warnings.simplefilter('ignore', DeprecationWarning) - import mailcap +mailcap = warnings_helper.import_deprecated('mailcap') # Location of mailcap file