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
using the trick defined in http://www.logilab.org/blogentry/78354, we could start adding to pylint a generic astng plugin that would help him to understand such things from the stdlib (there is also various tickets/comments about hashlib in the tracker).
That would be a great improvment indeed. Any volunteer ? :)
Beside this, I don't think there is other options than disabling the message.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With