-
-
Notifications
You must be signed in to change notification settings - Fork 147
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
Typing issues #212
Comments
It might help if you could provide details about the actual problem (by
clicking on the "View Problem" link, I suppose).
|
A typical example is shown in the UR of the screen capture: "Type of conn is unknown". This is what pylance shows when a type is missing, incomplete, or undetermined. Looking at the psycopg source, it seems that the type should be Connection, which inherits from BaseConnection[Row]. I know that pylance has difficulty with the type Row, and I wonder if its use in the definition of Connection might be the problem. |
@eykamp we use mypy as the reference type checker, which has no problem with the definition of the Connection. We even have tests that prove that typing code using psycopg works correctly. In you case, conn should be understood as a I assume from what I see that pylance is just a frontend to pyright, which does the real checking. If any you could try to run pyright on psycopg code to see if it understand everything. We are open to improvements for other checking tool, provided that they are not too invasive and don't break mypy. Closing this, because for sure the type returned by |
Thanks -- I suspect it is a pylance issue (I believe pyright was rolled into pylance and is no longer a going concern), but I was hoping someone here had some insight. If I can get it to work with mypy, which I'm sure I can, I'll report this to the pylance folks to see if it suggests a problem there. |
I reported this over at the pylance project, and their response was interesting and hopefully useful:
|
So apparently, it's "required" to annotate instance/class attributes even if they are assign a value: class BaseCursor(Generic[ConnectionType, Row]):
...
def __init__(self, connection: ConnectionType):
self._conn = connection
self.format = Format.TEXT # Missing type annotation for public attibute here Some pyright complaints on psycopg come from there. |
Psycopg codebase is checked with mypy --strict, which gives error if any single variable or function parameter has no type. We have 100% type coverage according to mypy rules, which infers correctly the type of every single variable or attribute we use. Pyright is broken. |
This is a pretty big backward incompatible change. I wonder if it has been discussed somewhere. |
This comes from python/typing#889 and there is a follow-up discussion at python/typing#913 (haven't read it completely, yet). I agree this is debatable. Not sure it should be discussed in terms of backwards compatibility because type checkers actually become more strict as they improve over time, so they're kind of always backward incompatible... |
I am pretty angry right now at that. I think I should add some notes to the conversation in python/typing#913 but now I'm too upset to be constructive. |
It appears that this version of psycopg is developed using typing throughout, which is fantastic. Unfortunately, something is not working for me using VSCode and pylance extension (see screenshot below). Is this a known issue, and if so, do you know if it is a pylance problem or a psycopg issue?
This code sample is from the Basic Usage documentation page, and it runs until it fails to connect, which proves the basic install is functional.
The text was updated successfully, but these errors were encountered: