如何防止python pylint抱怨socket类sendall方法 [英] How to prevent python pylint complaining about socket class sendall method
问题描述
我有一些代码使用简单的 tcp 套接字设置来测试某些内容.我们在我们的 python 文件上运行 pylint --errors-only
,通常作为验证我们所有代码的一种方式.
然而,python 套接字库文档中给出的简单示例代码 - http://docs.python.org/library/socket.html - 将输出:
************* 模块 SocketExampleE: 16: '_socketobject' 的实例没有 'recv' 成员E: 18: '_socketobject' 的实例没有 'sendall' 成员
文档显示了这些成员、代码运行和工作.
套接字目录也显示它们存在:
<预><代码>>>>进口插座>>>s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)>>>目录['__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']这归结为片段:
用于 _delegate_methods 中的方法:setattr(自我,方法,getattr(_sock,方法))
在 socket.py 实现中.
是否可以让 pylint 接受这种样式(并验证它),或者是使用 # pylint: disable-msg=E1101
忽略无成员"警告的唯一选择?
您可以使用 pylint --errors-only --ignored-classes=_socketobject
或添加
[类型检查]被忽略的类=SQLObject,_socketobject
到你的 ~/.pylintrc
文件.
来自文档,
<块引用>忽略的类:
成员属性的类名列表不应检查(对于具有动态属性的类很有用设置).
默认:SQLObject
I have a bit of code using a simple tcp socket setup to test something.
We run pylint --errors-only
on our python files, generally as a way to validate all our code.
However, the simple example code given on the python socket library documentation - http://docs.python.org/library/socket.html - will output:
************* Module SocketExample
E: 16: Instance of '_socketobject' has no 'recv' member
E: 18: Instance of '_socketobject' has no 'sendall' member
The documentation shows these members, the code runs and works.
A dir of socket shows them existing too:
>>> 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']
This is down to the snippet:
for method in _delegate_methods:
setattr(self, method, getattr(_sock, method))
In the socket.py implementation.
Can pylint be made to accept this style (and validate it) or is the only choice to ignore the "no member" warnings with # pylint: disable-msg=E1101
?
You can use pylint --errors-only --ignored-classes=_socketobject
or add
[TYPECHECK]
ignored-classes=SQLObject,_socketobject
to your ~/.pylintrc
file.
From the 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 pylint抱怨socket类sendall方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!