🌐 AI搜索 & 代理 主页
Skip to content

Commit 170dac2

Browse files
gh-76007: Deprecate __version__ attribute in http.server (#142658)
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
1 parent e02a35c commit 170dac2

File tree

6 files changed

+26
-5
lines changed

6 files changed

+26
-5
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Pending removal in Python 3.20
99
- :mod:`csv`
1010
- :mod:`!ctypes.macholib`
1111
- :mod:`decimal` (use :data:`decimal.SPEC_VERSION` instead)
12+
- :mod:`http.server`
1213
- :mod:`imaplib`
1314
- :mod:`ipaddress`
1415
- :mod:`json`

Doc/whatsnew/3.15.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,6 +1026,7 @@ New deprecations
10261026
- :mod:`csv`
10271027
- :mod:`!ctypes.macholib`
10281028
- :mod:`decimal` (use :data:`decimal.SPEC_VERSION` instead)
1029+
- :mod:`http.server`
10291030
- :mod:`imaplib`
10301031
- :mod:`ipaddress`
10311032
- :mod:`json`

Lib/http/server.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@
6161
# (Actually, the latter is only true if you know the server configuration
6262
# at the time the request was made!)
6363

64-
__version__ = "0.6"
65-
6664
__all__ = [
6765
"HTTPServer", "ThreadingHTTPServer",
6866
"HTTPSServer", "ThreadingHTTPSServer",
@@ -280,7 +278,7 @@ class BaseHTTPRequestHandler(socketserver.StreamRequestHandler):
280278
# The server software version. You may want to override this.
281279
# The format is multiple whitespace-separated strings,
282280
# where each string is of the form name[/version].
283-
server_version = "BaseHTTP/" + __version__
281+
server_version = "BaseHTTP"
284282

285283
error_message_format = DEFAULT_ERROR_MESSAGE
286284
error_content_type = DEFAULT_ERROR_CONTENT_TYPE
@@ -690,7 +688,7 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
690688
691689
"""
692690

693-
server_version = "SimpleHTTP/" + __version__
691+
server_version = "SimpleHTTP"
694692
index_pages = ("index.html", "index.htm")
695693
extensions_map = _encodings_map_default = {
696694
'.gz': 'application/gzip',
@@ -1080,5 +1078,14 @@ class HTTPSDualStackServer(DualStackServerMixin, ThreadingHTTPSServer):
10801078
)
10811079

10821080

1081+
def __getattr__(name):
1082+
if name == "__version__":
1083+
from warnings import _deprecated
1084+
1085+
_deprecated("__version__", remove=(3, 20))
1086+
return "0.6" # Do not change
1087+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
1088+
1089+
10831090
if __name__ == '__main__':
10841091
_main()

Lib/test/test_httpservers.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,6 +1560,16 @@ def test_https_client(self):
15601560
self.assertEqual(res, self.served_data)
15611561

15621562

1563+
class TestModule(unittest.TestCase):
1564+
def test_deprecated__version__(self):
1565+
with self.assertWarnsRegex(
1566+
DeprecationWarning,
1567+
"'__version__' is deprecated and slated for removal in Python 3.20",
1568+
) as cm:
1569+
getattr(http.server, "__version__")
1570+
self.assertEqual(cm.filename, __file__)
1571+
1572+
15631573
def setUpModule():
15641574
unittest.addModuleCleanup(os.chdir, os.getcwd())
15651575

Misc/NEWS.d/3.15.0a2.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ would raise an error.
583583
.. nonce: peEgcr
584584
.. section: Library
585585
586-
Deprecate ``__version__`` from a :mod:`imaplib`. Patch by Hugo van Kemenade.
586+
Deprecate ``__version__`` from :mod:`imaplib`. Patch by Hugo van Kemenade.
587587

588588
..
589589
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Deprecate ``__version__`` from :mod:`http.server`. Patch by Hugo van
2+
Kemenade.

0 commit comments

Comments
 (0)