Why is mypy complaining?
"socket" has no attribute "accept" [attr-defined]
import socket
def a() -> socket.SocketType:
...
b = a()
c, _ = b.accept()
It seems like the accept
method is present in stubs.
Why is mypy complaining?
"socket" has no attribute "accept" [attr-defined]
import socket
def a() -> socket.SocketType:
...
b = a()
c, _ = b.accept()
It seems like the accept
method is present in stubs.
1 Answer
Reset to default 1There is _socket
which is the underlying cpython implementation (socketmodule.c) and socket
(socket.py). See a related question here.
socket.SocketType
is actually _socket.socket
the internal class that is wrapped/subclassed by socket.socket
.
Only the child class socket.socket
from socket.py has the public accept
method. (Which is again a wrapper for _socket.socket._accept
)
-> socket.socket
? – Barmar Commented Jan 29 at 18:38socket.SocketType
was already being used. I replaced them withsocket.socket
and that resolved the error. – Sujay Commented Jan 29 at 18:49