Skip to content

Commit a80a38e

Browse files
[3.10] bpo-44498: Issue a deprecation warning on asynchat, asyncore and smtpd import (GH-26882) (GH-26904)
* Issue a deprecation warning on smtpd import * Also issue DeprecationWarnings for asynchat and asyncore * Fix some tests * test___all__ requires the word 'module' or 'package' in the deprecation warning text, so add those to smtpd, asynchat, and asyncore. * In test_support, use pprint now instead of asyncore as the landmark. * Add What's New * Use ..deprecated:: * Use ..deprecated:: * Update Lib/smtpd.py Co-authored-by: Miro Hrončok <[email protected]> * Update Doc/library/smtpd.rst Co-authored-by: Miro Hrončok <[email protected]> * Import async{hat,ore} after the DeprecationWarning for this module Co-authored-by: Miro Hrončok <[email protected]> (cherry picked from commit 8488b85c6397fe58f17fc00e047044c959ac0b04) Co-authored-by: Barry Warsaw <[email protected]> Automerge-Triggered-By: GH:warsaw
1 parent 11f1a30 commit a80a38e

File tree

6 files changed

+40
-9
lines changed

6 files changed

+40
-9
lines changed

Doc/library/smtpd.rst

+4-5
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@
1313

1414
This module offers several classes to implement SMTP (email) servers.
1515

16-
.. seealso::
17-
18-
The `aiosmtpd <http://aiosmtpd.readthedocs.io/>`_ package is a recommended
19-
replacement for this module. It is based on :mod:`asyncio` and provides a
20-
more straightforward API. :mod:`smtpd` should be considered deprecated.
16+
.. deprecated:: 3.6
17+
The `aiosmtpd <https://aiosmtpd.readthedocs.io/>`_ package is a recommended
18+
replacement for this module. It is based on :mod:`asyncio` and provides a
19+
more straightforward API.
2120

2221
Several server implementations are present; one is a generic
2322
do-nothing implementation, which can be overridden, while the other two offer

Doc/whatsnew/3.10.rst

+6
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,12 @@ The :meth:`~array.array.index` method of :class:`array.array` now has
883883
optional *start* and *stop* parameters.
884884
(Contributed by Anders Lorentsen and Zackery Spytz in :issue:`31956`.)
885885
886+
asynchat, asyncore, smtpd
887+
-------------------------
888+
These modules have been marked as deprecated in their module documentation
889+
since Python 3.6. An import-time :class:`DeprecationWarning` has now been
890+
added to all three of these modules.
891+
886892
base64
887893
------
888894

Lib/asynchat.py

+8
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@
4848
import asyncore
4949
from collections import deque
5050

51+
from warnings import warn
52+
warn(
53+
'The asynchat module is deprecated. '
54+
'The recommended replacement is asyncio',
55+
DeprecationWarning,
56+
stacklevel=2)
57+
58+
5159

5260
class async_chat(asyncore.dispatcher):
5361
"""This is an abstract class. You must derive from this class, and add

Lib/asyncore.py

+7
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@
5757
ENOTCONN, ESHUTDOWN, EISCONN, EBADF, ECONNABORTED, EPIPE, EAGAIN, \
5858
errorcode
5959

60+
warnings.warn(
61+
'The asyncore module is deprecated. '
62+
'The recommended replacement is asyncio',
63+
DeprecationWarning,
64+
stacklevel=2)
65+
66+
6067
_DISCONNECTED = frozenset({ECONNRESET, ENOTCONN, ESHUTDOWN, ECONNABORTED, EPIPE,
6168
EBADF})
6269

Lib/smtpd.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@
8383
import getopt
8484
import time
8585
import socket
86-
import asyncore
87-
import asynchat
8886
import collections
8987
from warnings import warn
9088
from email._header_value_parser import get_addr_spec, get_angle_addr
@@ -94,6 +92,19 @@
9492
"MailmanProxy",
9593
]
9694

95+
warn(
96+
'The smtpd module is deprecated and unmaintained. Please see aiosmtpd '
97+
'(https://aiosmtpd.readthedocs.io/) for the recommended replacement.',
98+
DeprecationWarning,
99+
stacklevel=2)
100+
101+
102+
# These are imported after the above warning so that users get the correct
103+
# deprecation warning.
104+
import asyncore
105+
import asynchat
106+
107+
97108
program = sys.argv[0]
98109
__version__ = 'Python SMTP proxy version 0.3'
99110

Lib/test/test_support.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,8 @@ def test_check_syntax_error(self):
292292

293293
def test_CleanImport(self):
294294
import importlib
295-
with import_helper.CleanImport("asyncore"):
296-
importlib.import_module("asyncore")
295+
with import_helper.CleanImport("pprint"):
296+
importlib.import_module("pprint")
297297

298298
def test_DirsOnSysPath(self):
299299
with import_helper.DirsOnSysPath('foo', 'bar'):

0 commit comments

Comments
 (0)