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

Co-authored-by: Victor Stinner <vstinner@python.org>
This commit is contained in:
Hugo van Kemenade 2025-10-20 15:20:44 +03:00 committed by GitHub
parent faa169afa0
commit 99c3c63d2b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 22 additions and 3 deletions

View 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)

View 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)

View file

@ -21,8 +21,6 @@
# 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 @@ 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}")

View file

@ -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()

View file

@ -0,0 +1 @@
Deprecate ``__version__`` from a :mod:`imaplib`. Patch by Hugo van Kemenade.