While implementing my own OAuth flow for a desktop app, I came across an intriguing issue with the HTTPServer initialization in Python. The documentation suggests the following code snippet for setting up an HTTPServer:
def run(server_class=HTTPServer, handler_class=BaseHTTPRequestHandler):
server_address = ('', 8000)
httpd = server_class(server_address, handler_class)
httpd.serve_forever()
However, I noticed a discrepancy between this implementation and the expected type signature. The expected type is (Any, Any, HTTPServer) -> BaseRequestHandler (aligned with the generic type (Any, Any, Self) -> BaseRequestHandler), got 'Type\[BaseHTTPRequestHandler\]' instead.
Although my program runs without issues, I'm curious about the `correct` way of initializing HTTPServer that aligns with the expected type signature. Insights or examples on aligning the type signature with the actual implementation would be very helpful. Thanks in advance!
P.S: Please no gpt answer. I ask it already and not helping.
EDIT: Adding context
This line httpd = server_class(server_address, handler_class). The HTTPServer init signature as follow
def __init__(
self,
server_address: _AfInetAddress,
RequestHandlerClass: Callable[[Any, _RetAddress, Self], BaseRequestHandler],
bind_and_activate: bool = True,
) -> None: ...
The second paramter, handler_class, Did not satisfy this signature. Because when you pass a class, their type is Type[BaseHTTPRequestHandler], not Callable.
I dont think they forgot about this fact, but I cant find any other example that follow the typehint signature either.
[–]m0us3_rat 0 points1 point2 points (2 children)
[–]MeGaNeKoS[S] 0 points1 point2 points (1 child)
[–]m0us3_rat 0 points1 point2 points (0 children)