]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-76007: Deprecate `__version__` attribute in `imaplib` (#140299)
authorHugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Mon, 20 Oct 2025 12:20:44 +0000 (15:20 +0300)
committerGitHub <noreply@github.com>
Mon, 20 Oct 2025 12:20:44 +0000 (15:20 +0300)
Co-authored-by: Victor Stinner <vstinner@python.org>
Doc/deprecations/pending-removal-in-3.20.rst
Doc/whatsnew/3.15.rst
Lib/imaplib.py
Lib/test/test_imaplib.py
Misc/NEWS.d/next/Library/2025-10-18-14-30-21.gh-issue-76007.peEgcr.rst [new file with mode: 0644]

index c86979c8ff91e98f6418b833a2655a7e49424e6b..21a561e7952afdce08d1969039fbb3c9eeba371b 100644 (file)
@@ -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)
index d3ae7c21a0358bc59db9bcea4274ed46ef7303fa..b360769b7e50fb5f75dc8537ad6f4c4fa3954422 100644 (file)
@@ -825,6 +825,7 @@ New deprecations
     - :mod:`argparse`
     - :mod:`csv`
     - :mod:`!ctypes.macholib`
+    - :mod:`imaplib`
     - :mod:`ipaddress`
     - :mod:`json`
     - :mod:`logging` (``__date__`` also deprecated)
index cbe129b3e7c2145cec06553c61f09984349ed730..c176736548188c34a97e4c10648938a238b02135 100644 (file)
@@ -21,8 +21,6 @@ Public functions:       Internaldate2tuple
 # GET/SETANNOTATION contributed by Tomas Lindroos <skitta@abo.fi> June 2005.
 # IDLE contributed by Forest <forestix@nom.one> 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 @@ class IMAP4:
             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 @@ try: %s -d5
 ''' % 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}")
index 999e6e69ab41eafd723556418761e3798da9ef46..430fa71fa29f59c23d410f268450d77149dc1764 100644 (file)
@@ -1117,5 +1117,15 @@ class ThreadedNetworkedTestsSSL(ThreadedNetworkedTests):
             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 (file)
index 0000000..be56b2c
--- /dev/null
@@ -0,0 +1 @@
+Deprecate ``__version__`` from a :mod:`imaplib`. Patch by Hugo van Kemenade.