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

psycopg2-stubs shadow typeshed stubs #74

Closed
ewjoachim opened this issue Dec 5, 2021 · 6 comments · Fixed by #196
Closed

psycopg2-stubs shadow typeshed stubs #74

ewjoachim opened this issue Dec 5, 2021 · 6 comments · Fixed by #196

Comments

@ewjoachim
Copy link

ewjoachim commented Dec 5, 2021

It took me a while to find that it was this package that caused my issue.

There are more complete stubs of psycopg2 in typeshed: https://github.com/python/typeshed/tree/master/stubs/psycopg2 which are automatically released as a PEP 561 package at https://pypi.org/project/types-psycopg2/

Installing both types-psycopg2 and django-types results in one unpredictibly shadowing the other, so mypy sometimes works and sometimes doesn't. Would you accept a PR that would remove psycopg2 types defined here and rely on the typeshed ones instead ?

@sbdchd
Copy link
Owner

sbdchd commented Dec 5, 2021

Yeah that works for me, the only downside I see is the types in the type shed aren't as fleshed out

@ewjoachim
Copy link
Author

ewjoachim commented Dec 5, 2021

I don't know if the stubs in typeshed are less complete.
What I can say is that psycopg2.extra.Json exists in typeshed and in psycopg2 but not in here. So does psycopg2.pool.

The people over at typeshed are quick to merge PRs, so it shouldn't be too hard to add missing stuff there.

@sbdchd
Copy link
Owner

sbdchd commented Dec 5, 2021

Yeah I think the type shed will have more stubs since it was created using stub gen, but right now they're a little thin on the type annotations

for instance parse_dsn is typed as Any -> Any and the connection cursor has an __enter__ return type of Any which means if we use the cursor like:

with connection.cursor() as conn:
    conn # this will be Any

@ewjoachim
Copy link
Author

Looking at the stubs here, I'm seeing that connection.cursor would return a cursor instance whose fetchone type is a Tuple. But if you configured your connection's cursor_factory to use a DictCursor, then fetchone will return a Dict. I know that it might not make a lot of sense in the context of Django, but this means we can have a lot of problems if the project uses psycopg2 directly alongside with Django.
Also... How do we know it's psycopg2 and not, say, MariaDB or sqlite ?

@sbdchd
Copy link
Owner

sbdchd commented Aug 17, 2022

Revisiting this, I think removing the psycopg2 types from this package and using the type shed ones is the way forward

@ewjoachim
Copy link
Author

(had completely forgotten about this issue. Not sure I have a lot of time to make a PR)

This was referenced Sep 10, 2023
@kodiakhq kodiakhq bot closed this as completed in #196 Sep 23, 2023
kodiakhq bot pushed a commit that referenced this issue Sep 23, 2023
This finishes the work done in #126. Commits are cherry-picked to give the original author credit.

I also removed psycopg2 tests as they are typeshed's problem now.

Fixes #74
Closes #126
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants