From b555fb87419490b57dd5912378d3f70270306280 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Sat, 18 Oct 2025 15:14:25 +0300 Subject: [PATCH 1/2] Deprecate __version__ attribute in imaplib --- Doc/deprecations/pending-removal-in-3.20.rst | 1 + Doc/whatsnew/3.15.rst | 1 + Lib/imaplib.py | 12 +++++++++--- Lib/test/test_imaplib.py | 10 ++++++++++ .../2025-10-18-14-30-21.gh-issue-76007.peEgcr.rst | 1 + 5 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2025-10-18-14-30-21.gh-issue-76007.peEgcr.rst diff --git a/Doc/deprecations/pending-removal-in-3.20.rst b/Doc/deprecations/pending-removal-in-3.20.rst index c86979c8ff91e9..21a561e7952afd 100644 --- a/Doc/deprecations/pending-removal-in-3.20.rst +++ b/Doc/deprecations/pending-removal-in-3.20.rst @@ -8,6 +8,7 @@ Pending removal in Python 3.20 - :mod:`argparse` - :mod:`csv` - :mod:`!ctypes.macholib` + - :mod:`imaplib` - :mod:`ipaddress` - :mod:`json` - :mod:`logging` (``__date__`` also deprecated) diff --git a/Doc/whatsnew/3.15.rst b/Doc/whatsnew/3.15.rst index d3ae7c21a0358b..b360769b7e50fb 100644 --- a/Doc/whatsnew/3.15.rst +++ b/Doc/whatsnew/3.15.rst @@ -825,6 +825,7 @@ New deprecations - :mod:`argparse` - :mod:`csv` - :mod:`!ctypes.macholib` + - :mod:`imaplib` - :mod:`ipaddress` - :mod:`json` - :mod:`logging` (``__date__`` also deprecated) diff --git a/Lib/imaplib.py b/Lib/imaplib.py index cbe129b3e7c214..b0361a79c9bed4 100644 --- a/Lib/imaplib.py +++ b/Lib/imaplib.py @@ -21,8 +21,6 @@ # GET/SETANNOTATION contributed by Tomas Lindroos June 2005. # IDLE contributed by Forest August 2024. -__version__ = "2.60" - import binascii, errno, random, re, socket, subprocess, sys, time, calendar from datetime import datetime, timezone, timedelta from io import DEFAULT_BUFFER_SIZE @@ -247,7 +245,6 @@ def _connect(self): self._cmd_log_idx = 0 self._cmd_log = {} # Last '_cmd_log_len' interactions if self.debug >= 1: - self._mesg('imaplib version %s' % __version__) self._mesg('new IMAP4 connection, tag=%s' % self.tagpre) self.welcome = self._get_response() @@ -1965,3 +1962,12 @@ def run(cmd, args): ''' % sys.argv[0]) raise + + +def __getattr__(name): + if name == "__version__": + from warnings import _deprecated + + _deprecated("__version__", remove=(3, 20)) + return "2.50" # Do not change + raise AttributeError(f"module {__name__!r} has no attribute {name!r}") diff --git a/Lib/test/test_imaplib.py b/Lib/test/test_imaplib.py index 999e6e69ab41ea..430fa71fa29f59 100644 --- a/Lib/test/test_imaplib.py +++ b/Lib/test/test_imaplib.py @@ -1117,5 +1117,15 @@ def test_ssl_verified(self): client.shutdown() +class TestModule(unittest.TestCase): + def test_deprecated__version__(self): + with self.assertWarnsRegex( + DeprecationWarning, + "'__version__' is deprecated and slated for removal in Python 3.20", + ) as cm: + getattr(imaplib, "__version__") + self.assertEqual(cm.filename, __file__) + + if __name__ == "__main__": unittest.main() diff --git a/Misc/NEWS.d/next/Library/2025-10-18-14-30-21.gh-issue-76007.peEgcr.rst b/Misc/NEWS.d/next/Library/2025-10-18-14-30-21.gh-issue-76007.peEgcr.rst new file mode 100644 index 00000000000000..be56b2ca6a1c97 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-10-18-14-30-21.gh-issue-76007.peEgcr.rst @@ -0,0 +1 @@ +Deprecate ``__version__`` from a :mod:`imaplib`. Patch by Hugo van Kemenade. From 74b0878ee5753d52db57f52dad792519d3fd4748 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Mon, 20 Oct 2025 12:06:17 +0300 Subject: [PATCH 2/2] Fix version number Co-authored-by: Victor Stinner --- Lib/imaplib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/imaplib.py b/Lib/imaplib.py index b0361a79c9bed4..c176736548188c 100644 --- a/Lib/imaplib.py +++ b/Lib/imaplib.py @@ -1969,5 +1969,5 @@ def __getattr__(name): from warnings import _deprecated _deprecated("__version__", remove=(3, 20)) - return "2.50" # Do not change + return "2.60" # Do not change raise AttributeError(f"module {__name__!r} has no attribute {name!r}")