You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Incorrect type declaration for http.server.BaseHTTPRequestHandler.__init__ #7160
This attribute is also not used in any of the defined methods on the BaseHTTPRequestHandler, it is used though in the setup method of the StreamRequestHandler seen here where it gets aliased to self.connection: https://github.com/python/cpython/blob/main/Lib/socketserver.py#L798
The type of the first parameter of http.server.BaseHTTPRequestHandler.__init__ shall be socketserver._RequestType, not bytes.
It seems to be like this in typeshed now. The issue is a bit more than four years from now, but still marked as opened. Indeed, it was likely bytes before. Reviewing something written about seven years ago, I had a BaseHTTPRequestHandler declaring to expect bytes for the request parameters. It was typechecked with MyPy, at that time. Now, reviewing everything, PyRight complained the type is not correct and say it should be as some people said in this thread : socket | tuple[bytes, socket].
May be the issue has been solved and it was forgotten to tag it as solved?
Activity
Akuli commentedon Feb 8, 2022
To me, it seems to always be a socket, so
_RequestTypeisn't great either as that would mean it's sometimestuple[bytes, socket].kkirsche commentedon Aug 18, 2022
Walking backwards through the cpython code:
http.server.BaseHTTPRequestHandlerdoesn't define an__init__method, rather it inherits it fromsocketserver.StreamRequestHandlersocketserver.StreamRequestHandleralso does not define an__init__method, inheriting it fromsocketserver.BaseRequestHandlersocketserver.BaseRequestHandlerdefines the__init__method.So, with that in mind, looking at
socketserver.BaseRequestHandlerin typeshed, the signature is defined as:The aliases here are defined as follows, while
BaseServeris asocketserverclass:So with this in mind, if we look at the Python page's documentation, the
requestattribute isn't mentioned in any way:https://docs.python.org/3/library/http.server.html#http.server.BaseHTTPRequestHandler
This attribute is also not used in any of the defined methods on the
BaseHTTPRequestHandler, it is used though in thesetupmethod of theStreamRequestHandlerseen here where it gets aliased toself.connection:https://github.com/python/cpython/blob/main/Lib/socketserver.py#L798
Since this attempts to call instance methods on this value without any form of type checking, I would say this is correctly typed even though it's not necessarily correctly modeled:
https://github.com/python/cpython/blob/main/Lib/socketserver.py#L801
Hibou57 commentedon Sep 22, 2026
It seems to be like this in typeshed now. The issue is a bit more than four years from now, but still marked as opened. Indeed, it was likely
bytesbefore. Reviewing something written about seven years ago, I had aBaseHTTPRequestHandlerdeclaring to expectbytesfor the request parameters. It was typechecked with MyPy, at that time. Now, reviewing everything, PyRight complained the type is not correct and say it should be as some people said in this thread :socket | tuple[bytes, socket].May be the issue has been solved and it was forgotten to tag it as solved?
iamahuman commentedon Sep 22, 2026
Fixed in #9055.