最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - "socket" has no attribute "accept" - Stack Overflow

programmeradmin0浏览0评论

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.

Share Improve this question edited Jan 30 at 18:38 Remy Lebeau 601k36 gold badges508 silver badges851 bronze badges asked Jan 29 at 18:30 SujaySujay 3752 silver badges9 bronze badges 2
  • I'm not sure what the difference is, but why not -> socket.socket? – Barmar Commented Jan 29 at 18:38
  • 1 @Barmar socket.SocketType was already being used. I replaced them with socket.socket and that resolved the error. – Sujay Commented Jan 29 at 18:49
Add a comment  | 

1 Answer 1

Reset to default 1

There 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)

发布评论

评论列表(0)

  1. 暂无评论