Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Doc/deprecations/pending-removal-in-3.20.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -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)
Expand Down
1 change: 1 addition & 0 deletions Doc/whatsnew/3.15.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -825,6 +825,7 @@ New deprecations
- :mod:`argparse`
- :mod:`csv`
- :mod:`!ctypes.macholib`
- :mod:`imaplib`
- :mod:`ipaddress`
- :mod:`json`
- :mod:`logging` (``__date__`` also deprecated)
Expand Down
12 changes: 9 additions & 3 deletions Lib/imaplib.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -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
Expand DownExpand Up@@ -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()
Expand DownExpand Up@@ -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}")
10 changes: 10 additions & 0 deletions Lib/test/test_imaplib.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -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()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
Deprecate ``__version__`` from a :mod:`imaplib`. Patch by Hugo van Kemenade.
Loading