How to prevent python pylint complaining about sendall class socket method

I have some code using a simple tcp socket setup to test something. We run pylint --errors-only in our python files, usually to test all our code.

However, a simple example code provided in the python socket library documentation - http://docs.python.org/library/socket.html - outputs:

 ************* 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 works and works.

A disk from the socket also shows them:

 >>> 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 refers to the snippet:

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

In the implementation of socket.py.

Is it possible to get this style to be accepted (and test it) or is it the only choice to ignore the "no member" warnings with # pylint: disable-msg=E1101 ?

+8
python pylint
source share
2 answers

You can use pylint --errors-only --ignored-classes=_socketobject or add

 ignored-classes=SQLObject,_socketobject 

into your ~/.pylintrc file.

From documenation ,

ignored classes

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

Default: SQLObject

+7
source share

using the trick defined at http://www.logilab.org/blogentry/78354 , we could start adding a generic astng plugin to pylint that would help him understand such things from stdlib (there are also various tickets / comments about the hashlib in the tracker )

It really would be a great success. Any volunteer? :)

Also, I don't think there are other options besides disabling the message.

+1
source share

All Articles