shepster
shepster

Reputation: 509

Why do I get the pylint error: Module 'socket' has no 'gethostname' member (no-member)?

I have the following code example:

#!/usr/bin/python3
'''Why do I get the pylint error Module 'socket' has no 'gethostname' member (no-member)?'''
import socket
print(socket.gethostname())

Which runs fine and prints the hostname as output.

However, when I check with pylint I get an error:

% pylint testSocket.py
************* Module testSocket
testSocket.py:7:6: E1101: Module 'socket' has no 'gethostname' member (no-member)

----------------------------------------------------------------------
Your code has been rated at -15.00/10 (previous run: -20.00/10, +5.00)

%

This is a super-trimmed down example. In my full-fledged code I play with other socket functions such as socket.getfqdn(), or socket.gethostbyname(nDict['HOST_FQDN']) with no pylint issues.

Even within the socket module it includes the following line under Functions:

    gethostname() -- return the current hostname

How can I get a clean run of pylint? (Without resorting to # pylint: disable=E1101)

Python 3.8.2, pylint 2.7.2

Upvotes: 3

Views: 1076

Answers (1)

Pierre.Sassoulas
Pierre.Sassoulas

Reputation: 4282

There is an issue with some environment (MacOs for example) in pylint right now. As a workaround, if you install your environment with pyenv, it will recompile some package and works. See this comment

When I first stumbled over this I made a list to check what the culprits are, and it boiled down to two modules: socket (socket.error, socket.AF_INET, socket.SOCK_STREAM), math (math.log10, math.pi, math.ceil, math.sqrt)

For example, the math.log10 is found in math.pyi (i.e. the stub file) when using command+SHIFT to jump to source. Maybe those stub files are not installed correctly with some installation methods. I'll try to figure out where they should live - if I jump from VScode to the .pyi file, it opens one of the fallback stub files provided by the Pylance plugin for VScode.

Upvotes: 2

Related Questions