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

E1101: Class 'value' has no 'any' member (no-member) for psycopg connection class #10222

Open
sashko1988 opened this issue Feb 4, 2025 · 2 comments
Labels
Lib specific 💅 This affect the code from a particular library

Comments

@sashko1988
Copy link

sashko1988 commented Feb 4, 2025

Bug description

Pylint can't resolve psycopg connection class members if the connection is assigned to a variable before using its context manager.

that fails:

"""dummy docstring"""
import psycopg

client = psycopg.connect("dbname=test user=postgres")
with client:
    version = client.execute(
        """
        CREATE TABLE test (
            id serial PRIMARY KEY,
            num integer,
            data text)
        """
    ).fetchone()

while the following passes:

"""dummy docstring"""
import psycopg


with psycopg.connect("dbname=test user=postgres") as client:
    version = client.execute(
        """
        CREATE TABLE test (
            id serial PRIMARY KEY,
            num integer,
            data text)
        """
    ).fetchone()

Configuration

Command used

pylint src/strange_stuff/failing_module.py

Pylint output

************* Module strange_stuff.failing_module
src/strange_stuff/failing_module.py:6:14: E1101: Class 'value' has no 'execute' member (no-member)

Expected behavior

No error triggered

Pylint version

pylint 3.3.4
astroid 3.3.8
Python 3.12.8 (main, Dec 10 2024, 14:53:19) [Clang 16.0.0 (clang-1600.0.26.4)]

OS / Environment

macos 15.3, ubuntu 22.04

Additional dependencies

astroid==3.3.8
dill==0.3.9
isort==6.0.0
mccabe==0.7.0
platformdirs==4.3.6
psycopg==3.2.4
pyenchant==3.2.2
pylint==3.3.4
tomlkit==0.13.2
typing_extensions==4.12.2
@sashko1988 sashko1988 added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Feb 4, 2025
@zenlyj zenlyj added Lib specific 💅 This affect the code from a particular library and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Feb 5, 2025
@jtkmckenna
Copy link

Came here to reference my issue on psycopg (and how it got listed as a pylint issue there) psycopg/psycopg#1003

My example was similar:

"""Module docstring."""
import psycopg

def get_cursor():
    """Function docstring."""
    conn = psycopg.connect("dbname=news")
    return conn.cursor()

Getting a warning:

pip install psycopg==3.2.4
pylint my_test_file.py

************* Modulemy_test_file
bad_psycopg.py:7:11: E1101: Class 'value' has no 'cursor' member (no-member)
------------------------------------------------------------------
Your code has been rated at 0.00/10 (previous run: 0.00/10, +0.00)

@sashko1988
Copy link
Author

@jtkmckenna, nice investigation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Lib specific 💅 This affect the code from a particular library
Projects
None yet
Development

No branches or pull requests

3 participants