https://github.com/python/cpython/commit/99c3c63d2b22359374ecb9645b027b8cd2082249
commit: 99c3c63d2b22359374ecb9645b027b8cd2082249
branch: main
author: Hugo van Kemenade <[email protected]>
committer: hugovk <[email protected]>
date: 2025-10-20T15:20:44+03:00
summary:

gh-76007: Deprecate `__version__` attribute in `imaplib` (#140299)

Co-authored-by: Victor Stinner <[email protected]>

files:
A Misc/NEWS.d/next/Library/2025-10-18-14-30-21.gh-issue-76007.peEgcr.rst
M Doc/deprecations/pending-removal-in-3.20.rst
M Doc/whatsnew/3.15.rst
M Lib/imaplib.py
M Lib/test/test_imaplib.py

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..c176736548188c 100644
--- a/Lib/imaplib.py
+++ b/Lib/imaplib.py
@@ -21,8 +21,6 @@
 # GET/SETANNOTATION contributed by Tomas Lindroos <[email protected]> June 2005.
 # IDLE contributed by Forest <[email protected]> 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.60"  # 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.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to