Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positives in socket library #4798

Closed
nodeg opened this issue Aug 4, 2021 · 9 comments · Fixed by #5529
Closed

False positives in socket library #4798

nodeg opened this issue Aug 4, 2021 · 9 comments · Fixed by #5529
Labels
Bug 🪲 False Positive 🦟 A message is emitted but nothing is wrong with the code macOS
Milestone

Comments

@nodeg
Copy link

nodeg commented Aug 4, 2021

Bug description

Pylint complains about non existent members in the socket library of Python, although they exist according to the docu.

Sample code:

#!/usr/bin/python3

"""
socket_test.py
Pylint test for the socket library
"""
import socket


HOSTNAME = "suse.com"
IPADDR = ""

try:
    IPADDR = socket.gethostbyname_ex(HOSTNAME)
except socket.gaierror:
    IPADDR = "10.0.0.1"
print(IPADDR)

Configuration

No response

Command used

pylint socket_test.py

Pylint output

************* Module socket_test
socket_test.py:13:13: E1101: Module 'socket' has no 'gethostbyname_ex' member (no-member)
socket_test.py:14:7: E1101: Module 'socket' has no 'gaierror' member (no-member)

---------------------------------------------------------------------
Your code has been rated at -4.29/10 (previous run: -12.86/10, +8.57)

Expected behavior

Pylint should pass without error.

Pylint version

pylint 2.8.3
astroid 2.5.6
Python 3.8.10 (default, May 05 2021, 15:36:36) [GCC]

OS / Environment

openSUSE Tumbleweed

Additional dependencies

No response

@nodeg nodeg added Bug 🪲 Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Aug 4, 2021
@Pierre-Sassoulas Pierre-Sassoulas added Cannot reproduce 🤷 and removed Bug 🪲 Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Aug 4, 2021
@Pierre-Sassoulas
Copy link
Member

I don't have any problem with the latest pylint, what happen if you use 2.9.6 or the latest master ?

@nodeg
Copy link
Author

nodeg commented Aug 5, 2021

I updated pylint with pipx and still got the same issue:

$ pipx upgrade-all
(...)              
upgraded package pylint from 2.8.3 to 2.9.6 (location: /home/dom/.local/pipx/venvs/pylint)
(...)

$ pylint --version
pylint 2.9.6
astroid 2.6.6
Python 3.8.10 (default, May 05 2021, 15:36:36) [GCC]

$ pylint socket_test.py
************* Module socket_test
socket_test.py:13:13: E1101: Module 'socket' has no 'gethostbyname_ex' member (no-member)
socket_test.py:14:7: E1101: Module 'socket' has no 'gaierror' member (no-member)

--------------------------------------------------------------------
Your code has been rated at -2.50/10 (previous run: -2.50/10, +0.00)

The master branch did not work for me either:

$ pylint --version
pylint 2.10.0-dev0
astroid 2.6.6
Python 3.8.10 (default, May 05 2021, 15:36:36) [GCC]

$ pylint socket_test.py
************* Module socket_test
socket_test.py:13:13: E1101: Module 'socket' has no 'gethostbyname_ex' member (no-member)
socket_test.py:14:7: E1101: Module 'socket' has no 'gaierror' member (no-member)

------------------------------------
Your code has been rated at -2.50/10

Any suggestions?

@Pierre-Sassoulas
Copy link
Member

Could you provide your list of dependencies ? Or if you don't have one the result of pip freeze ? :)

@nodeg
Copy link
Author

nodeg commented Aug 5, 2021

I installed pylint via pipx and not via pip.

$ pip freeze
appdirs==1.4.4
attrs==21.2.0
chardet==4.0.0
cli-test-helpers==1.0.1
iniconfig==1.1.1
ordered-set==4.0.2
packaging==21.0
pep517==0.11.0
pluggy==0.13.1
psutil==5.8.0
py==1.10.0
pycurl==7.43.0.6
PyGObject==3.40.1
pyparsing==2.4.7
pytest==6.2.4
six==1.16.0
toml==0.10.2
tomli==1.2.0
wfuzz==3.1.0

$ pipx list
venvs are in /home/dom/.local/pipx/venvs
apps are exposed on your $PATH at /home/dom/.local/bin
   package bpytop 1.0.67, Python 3.8.10
    - bpytop
   package dirsearch 0.4.2, Python 3.8.10
    - dirsearch
   package pylint 2.9.6, Python 3.8.10
    - epylint
    - pylint
    - pyreverse
    - symilar
   package sqlmap 1.5.8, Python 3.8.10
    - sqlmap
   package virtualenv 20.7.0, Python 3.8.10
    - virtualenv

@Pierre-Sassoulas
Copy link
Member

Still can't reproduce with:

pylint 2.9.6
astroid 2.6.6
Python 3.8.10 (default, Jun  2 2021, 10:49:15) 
[GCC 9.4.0]

Using the same code and same name, after sudo apt install libcurl4-openssl-dev libssl-dev libcairo2-dev libgirepository1.0-dev, upgrading pip and installing latest wheel + installing the dependencies from your pip freeze.

@DudeNr33
Copy link
Collaborator

DudeNr33 commented Aug 7, 2021

This looks very similar to the problem discussed in #4759 - some modules implemented in C give false-positive no-member or similar errors for socket and math (and possibly also for other C modules in the standard library).

In this case it depended on the way Python itself has been installed, but I did not figure out yet what the core problem is.

I can confirm that socket.gaierror and socket.gethostbyname_ex() also trigger no-member in my Homebrew-installed Python3.9 environment on macOS 11.4 Big Sur:

pylint 2.10.0-dev0
astroid 2.6.5
Python 3.9.6 (default, Jun 28 2021, 19:24:41) 
[Clang 12.0.5 (clang-1205.0.22.9)]

@Pierre-Sassoulas Pierre-Sassoulas added Bug 🪲 False Positive 🦟 A message is emitted but nothing is wrong with the code macOS and removed Cannot reproduce 🤷 labels Aug 7, 2021
@nodeg
Copy link
Author

nodeg commented Aug 7, 2021

Thanks for the comment @DudeNr33. I can confirm the issue on macOS using Homebrew, too.

$ pylint --version
pylint 2.9.6
astroid 2.6.6
Python 3.9.6 (default, Jun 29 2021, 05:25:02) 
[Clang 12.0.5 (clang-1205.0.22.9)]

$ pylint socket_test.py
************* Module socket_test
socket_test.py:14:13: E1101: Module 'socket' has no 'gethostbyname_ex' member (no-member)
socket_test.py:15:7: E1101: Module 'socket' has no 'gaierror' member (no-member)

------------------------------------
Your code has been rated at -2.50/10

@DudeNr33
Copy link
Collaborator

DudeNr33 commented Aug 8, 2021

You can try to use pyenv to manage the Python installations for you - this helped me and another user to get rid of those false positives.
It seems like pyenv compiles CPython from source, so doing that yourself might be another option (until a true fix for this issue is found).

@nodeg
Copy link
Author

nodeg commented Aug 9, 2021

Thanks for the suggestions. I have no problems with the pylint result since I know that those socket methods do exist. I just wanted to report these false positives.

@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.13.0 milestone Dec 15, 2021
Pierre-Sassoulas added a commit that referenced this issue Dec 15, 2021
Closes #3499
Closes #4302
Closes #4798
Closes #5081
Pierre-Sassoulas added a commit that referenced this issue Dec 19, 2021
Closes #1470
Closes #3499
Closes #4302
Closes #4798
Closes #5081
Pierre-Sassoulas added a commit that referenced this issue Dec 31, 2021
Closes #1470
Closes #3499
Closes #4302
Closes #4798
Closes #5081
Pierre-Sassoulas added a commit that referenced this issue Dec 31, 2021
Closes #1470
Closes #3499
Closes #4302
Closes #4798
Closes #5081
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue Jan 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🪲 False Positive 🦟 A message is emitted but nothing is wrong with the code macOS
Projects
None yet
3 participants