gpt4 book ai didi

python - 如何防止 python pylint 提示套接字类 sendall 方法

转载 作者:太空狗 更新时间:2023-10-29 20:21:55 26 4
gpt4 key购买 nike

我有一些代码使用简单的 tcp 套接字设置来测试某些东西。我们在 python 文件上运行 pylint --errors-only,通常作为验证我们所有代码的一种方式。

但是,python 套接字库文档中给出的简单示例代码 - http://docs.python.org/library/socket.html - 将输出:

************* Module SocketExample
E: 16: Instance of '_socketobject' has no 'recv' member
E: 18: Instance of '_socketobject' has no 'sendall' member

文档显示了这些成员,代码运行并工作。

套接字目录显示它们也存在:

>>> import socket
>>> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>> dir(s)
['__class__', '__delattr__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__slots__', '__str__', '__subclasshook__', '__weakref__', '_sock', 'accept', 'bind', 'close', 'connect', 'connect_ex', 'dup', 'family', 'fileno', 'getpeername', 'getsockname', 'getsockopt', 'gettimeout', 'listen', 'makefile', 'proto', 'recv', 'recv_into', 'recvfrom', 'recvfrom_into', 'send', 'sendall', 'sendto', 'setblocking', 'setsockopt', 'settimeout', 'shutdown', 'type']

这取决于代码段:

   for method in _delegate_methods:
setattr(self, method, getattr(_sock, method))

在 socket.py 实现中。

可以让 pylint 接受这种风格(并验证它)还是使用 # pylint: disable-msg=E1101 忽略“无成员”警告的唯一选择?

最佳答案

您可以使用 pylint --errors-only --ignored-classes=_socketobject 或添加

[TYPECHECK]
ignored-classes=SQLObject,_socketobject

到你的 ~/.pylintrc 文件。

来自documenation ,

ignored-classes:

List of classes names for which member attributes should not be checked (useful for classes with attributes dynamically set).

Default: SQLObject

关于python - 如何防止 python pylint 提示套接字类 sendall 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10300082/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com