]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-76007: Deprecate `__version__` attribute in `http.server` (#142658)
authorHugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Sat, 13 Dec 2025 15:32:13 +0000 (17:32 +0200)
committerGitHub <noreply@github.com>
Sat, 13 Dec 2025 15:32:13 +0000 (15:32 +0000)
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Doc/deprecations/pending-removal-in-3.20.rst
Doc/whatsnew/3.15.rst
Lib/http/server.py
Lib/test/test_httpservers.py
Misc/NEWS.d/3.15.0a2.rst
Misc/NEWS.d/next/Library/2025-12-13-00-09-09.gh-issue-76007.Xg1xCO.rst [new file with mode: 0644]

index c0feda1968258dcbea84f8ba09d04f236a8c0601..1e517531c953e9fff549216db52f50facd1d0c70 100644 (file)
@@ -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`
index afefcc15ab2d558d09c43837e2d4045c963ecbbf..a94486dd4805bdf90d2d688ec0645812844dcb32 100644 (file)
@@ -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`
index 160d3eefc7cbdf9a39100c69c1f99fe093467039..9c9cfbce421343be203242ea80d609a311f85641 100644 (file)
@@ -61,8 +61,6 @@ XXX To do:
 # (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 @@ def _main(args=None):
     )
 
 
+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()
index 7da5e3a19575889f7a8ba393a01cef0b3430704e..0dc5c9dbaed5d81f62fe60dfdd9d3f3ff63d82af 100644 (file)
@@ -1560,6 +1560,16 @@ class CommandLineRunTimeTestCase(unittest.TestCase):
         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())
 
index 4e3a62b0f4a7d2aa6c3101aeb4d68896acc98aef..4329d8c6bc2265f015b79c666e608c605b4d53a6 100644 (file)
@@ -583,7 +583,7 @@ would raise an error.
 .. nonce: peEgcr
 .. section: Library
 
-Deprecate ``__version__`` from :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 (file)
index 0000000..48e9d30
--- /dev/null
@@ -0,0 +1,2 @@
+Deprecate ``__version__`` from :mod:`http.server`. Patch by Hugo van
+Kemenade.