Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Deprecate __version__ attribute in http.server
  • Loading branch information
hugovk committed Dec 12, 2025
commit 1156c53d94ba6e0d63cac8556a32cfbc983e76de
1 change: 1 addition & 0 deletions Doc/deprecations/pending-removal-in-3.20.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
1 change: 1 addition & 0 deletions Doc/whatsnew/3.15.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
15 changes: 11 additions & 4 deletions Lib/http/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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()
10 changes: 10 additions & 0 deletions Lib/test/test_httpservers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Deprecate ``__version__`` from a :mod:`http.server`. Patch by Hugo van
Comment thread
hugovk marked this conversation as resolved.
Outdated
Kemenade.
Loading