Skip to content

Commit 99c3c63

Browse files
hugovkvstinner
andauthored
gh-76007: Deprecate __version__ attribute in imaplib (#140299)
Co-authored-by: Victor Stinner <[email protected]>
1 parent faa169a commit 99c3c63

File tree

5 files changed

+22
-3
lines changed

5 files changed

+22
-3
lines changed

Doc/deprecations/pending-removal-in-3.20.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Pending removal in Python 3.20
88
- :mod:`argparse`
99
- :mod:`csv`
1010
- :mod:`!ctypes.macholib`
11+
- :mod:`imaplib`
1112
- :mod:`ipaddress`
1213
- :mod:`json`
1314
- :mod:`logging` (``__date__`` also deprecated)

Doc/whatsnew/3.15.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,7 @@ New deprecations
825825
- :mod:`argparse`
826826
- :mod:`csv`
827827
- :mod:`!ctypes.macholib`
828+
- :mod:`imaplib`
828829
- :mod:`ipaddress`
829830
- :mod:`json`
830831
- :mod:`logging` (``__date__`` also deprecated)

Lib/imaplib.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
# GET/SETANNOTATION contributed by Tomas Lindroos <[email protected]> June 2005.
2222
# IDLE contributed by Forest <[email protected]> August 2024.
2323

24-
__version__ = "2.60"
25-
2624
import binascii, errno, random, re, socket, subprocess, sys, time, calendar
2725
from datetime import datetime, timezone, timedelta
2826
from io import DEFAULT_BUFFER_SIZE
@@ -247,7 +245,6 @@ def _connect(self):
247245
self._cmd_log_idx = 0
248246
self._cmd_log = {} # Last '_cmd_log_len' interactions
249247
if self.debug >= 1:
250-
self._mesg('imaplib version %s' % __version__)
251248
self._mesg('new IMAP4 connection, tag=%s' % self.tagpre)
252249

253250
self.welcome = self._get_response()
@@ -1965,3 +1962,12 @@ def run(cmd, args):
19651962
''' % sys.argv[0])
19661963

19671964
raise
1965+
1966+
1967+
def __getattr__(name):
1968+
if name == "__version__":
1969+
from warnings import _deprecated
1970+
1971+
_deprecated("__version__", remove=(3, 20))
1972+
return "2.60" # Do not change
1973+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")

Lib/test/test_imaplib.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,5 +1117,15 @@ def test_ssl_verified(self):
11171117
client.shutdown()
11181118

11191119

1120+
class TestModule(unittest.TestCase):
1121+
def test_deprecated__version__(self):
1122+
with self.assertWarnsRegex(
1123+
DeprecationWarning,
1124+
"'__version__' is deprecated and slated for removal in Python 3.20",
1125+
) as cm:
1126+
getattr(imaplib, "__version__")
1127+
self.assertEqual(cm.filename, __file__)
1128+
1129+
11201130
if __name__ == "__main__":
11211131
unittest.main()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Deprecate ``__version__`` from a :mod:`imaplib`. Patch by Hugo van Kemenade.

0 commit comments

Comments
 (0)