https://github.com/python/cpython/commit/170dac291edc385cf5b46e09c6481be409e0633a
commit: 170dac291edc385cf5b46e09c6481be409e0633a
branch: main
author: Hugo van Kemenade <[email protected]>
committer: hugovk <[email protected]>
date: 2025-12-13T15:32:13Z
summary:

gh-76007: Deprecate `__version__` attribute in `http.server` (#142658)

Co-authored-by: Stan Ulbrych <[email protected]>

files:
A Misc/NEWS.d/next/Library/2025-12-13-00-09-09.gh-issue-76007.Xg1xCO.rst
M Doc/deprecations/pending-removal-in-3.20.rst
M Doc/whatsnew/3.15.rst
M Lib/http/server.py
M Lib/test/test_httpservers.py
M Misc/NEWS.d/3.15.0a2.rst

diff --git a/Doc/deprecations/pending-removal-in-3.20.rst 
b/Doc/deprecations/pending-removal-in-3.20.rst
index c0feda1968258d..1e517531c953e9 100644
--- a/Doc/deprecations/pending-removal-in-3.20.rst
+++ b/Doc/deprecations/pending-removal-in-3.20.rst
@@ -9,6 +9,7 @@ Pending removal in Python 3.20
   - :mod:`csv`
   - :mod:`!ctypes.macholib`
   - :mod:`decimal` (use :data:`decimal.SPEC_VERSION` instead)
+  - :mod:`http.server`
   - :mod:`imaplib`
   - :mod:`ipaddress`
   - :mod:`json`
diff --git a/Doc/whatsnew/3.15.rst b/Doc/whatsnew/3.15.rst
index afefcc15ab2d55..a94486dd4805bd 100644
--- a/Doc/whatsnew/3.15.rst
+++ b/Doc/whatsnew/3.15.rst
@@ -1026,6 +1026,7 @@ New deprecations
     - :mod:`csv`
     - :mod:`!ctypes.macholib`
     - :mod:`decimal` (use :data:`decimal.SPEC_VERSION` instead)
+    - :mod:`http.server`
     - :mod:`imaplib`
     - :mod:`ipaddress`
     - :mod:`json`
diff --git a/Lib/http/server.py b/Lib/http/server.py
index 160d3eefc7cbdf..9c9cfbce421343 100644
--- a/Lib/http/server.py
+++ b/Lib/http/server.py
@@ -61,8 +61,6 @@
 # (Actually, the latter is only true if you know the server configuration
 # at the time the request was made!)
 
-__version__ = "0.6"
-
 __all__ = [
     "HTTPServer", "ThreadingHTTPServer",
     "HTTPSServer", "ThreadingHTTPSServer",
@@ -280,7 +278,7 @@ class 
BaseHTTPRequestHandler(socketserver.StreamRequestHandler):
     # The server software version.  You may want to override this.
     # The format is multiple whitespace-separated strings,
     # where each string is of the form name[/version].
-    server_version = "BaseHTTP/" + __version__
+    server_version = "BaseHTTP"
 
     error_message_format = DEFAULT_ERROR_MESSAGE
     error_content_type = DEFAULT_ERROR_CONTENT_TYPE
@@ -690,7 +688,7 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
 
     """
 
-    server_version = "SimpleHTTP/" + __version__
+    server_version = "SimpleHTTP"
     index_pages = ("index.html", "index.htm")
     extensions_map = _encodings_map_default = {
         '.gz': 'application/gzip',
@@ -1080,5 +1078,14 @@ class HTTPSDualStackServer(DualStackServerMixin, 
ThreadingHTTPSServer):
     )
 
 
+def __getattr__(name):
+    if name == "__version__":
+        from warnings import _deprecated
+
+        _deprecated("__version__", remove=(3, 20))
+        return "0.6"  # Do not change
+    raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
+
+
 if __name__ == '__main__':
     _main()
diff --git a/Lib/test/test_httpservers.py b/Lib/test/test_httpservers.py
index 7da5e3a1957588..0dc5c9dbaed5d8 100644
--- a/Lib/test/test_httpservers.py
+++ b/Lib/test/test_httpservers.py
@@ -1560,6 +1560,16 @@ def test_https_client(self):
         self.assertEqual(res, self.served_data)
 
 
+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(http.server, "__version__")
+        self.assertEqual(cm.filename, __file__)
+
+
 def setUpModule():
     unittest.addModuleCleanup(os.chdir, os.getcwd())
 
diff --git a/Misc/NEWS.d/3.15.0a2.rst b/Misc/NEWS.d/3.15.0a2.rst
index 4e3a62b0f4a7d2..4329d8c6bc2265 100644
--- a/Misc/NEWS.d/3.15.0a2.rst
+++ b/Misc/NEWS.d/3.15.0a2.rst
@@ -583,7 +583,7 @@ would raise an error.
 .. nonce: peEgcr
 .. section: Library
 
-Deprecate ``__version__`` from a :mod:`imaplib`. Patch by Hugo van Kemenade.
+Deprecate ``__version__`` from :mod:`imaplib`. Patch by Hugo van Kemenade.
 
 ..
 
diff --git 
a/Misc/NEWS.d/next/Library/2025-12-13-00-09-09.gh-issue-76007.Xg1xCO.rst 
b/Misc/NEWS.d/next/Library/2025-12-13-00-09-09.gh-issue-76007.Xg1xCO.rst
new file mode 100644
index 00000000000000..48e9d30497716e
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-12-13-00-09-09.gh-issue-76007.Xg1xCO.rst
@@ -0,0 +1,2 @@
+Deprecate ``__version__`` from :mod:`http.server`. Patch by Hugo van
+Kemenade.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to