-
Notifications
You must be signed in to change notification settings - Fork 768
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
Pylance failing with psycopg #2267
Comments
This library is marked as "py.typed", which means that it is claiming to be fully typed. While it does contain some type information, some of the symbols are lacking type annotations. Pyright (the type checker that pylance is built upon) has a command-line option "--verifytypes" that you can run on a "py.typed" library to determine its "type completeness". When I run
For "py.typed" libraries, pyright (and pylance) rely on type annotations. Symbols that have no type annotations are assumed to be "Any" / "Unknown". Guidance for library maintainers can be found here. Pyright fully implements this guidance, whereas mypy has not yet been updated to comply with these rules. That explains why you are seeing the difference between the two type checkers. If this library is important to you, please reach out to the maintainer and recommend that they add the missing type annotations. And if they have any questions, we're happy to assist. In the meantime, consumers of psycopg have a couple of options:
|
Ok, thank you!!! |
Hello,
I have been reported that pylance reports this attribute as untyped:
I have read the reference document and
It is overly bureaucratic to require I would like this detail of the spec to be discussed instead of being implemented by a tool, called a standard, and declaring other tools not updated. |
Hi @dvarrazzo, thanks for reaching out to us. I see that you’re the maintainer of the psycopg library. This might not be the best forum for this discussion since this is a closed issue in pylance. It might be better to create a new discussion in the python/typing project. That is where the active members of the Python typing community tend to hang out, and it would give it more visibility and allow others to participate. I can understand how it may appear that a type annotation for a class variable “height” serves no use here, but there are some factors that you may not be aware of. First, a value assignment and a type declaration have very different meanings to a static type analyzer. A value assignment (such as Second, while we’re open to the idea of standardizing certain special cases where value assignments imply the same thing as a type declaration, specifying those special cases has proven to be complicated. If we allow Like I said, it’s probably best to move this discussion to a more public forum so others can participate. |
Most of the example you point at are well understood by the type inference rules that mypy produces and I see no reason why class attributes must follow a different, stricter rule compared to local variable. If I will follow your advice to write to python typing. |
VS Code/pylance are flagging lots of errors with psycopg (v3, which has type hints baked in to everything, not v2 which doesn't). Using the sample code flags lots of things as having missing types, but looking at the source shows everything seems tightly typed. I haven't tried, but the psycopg devs swear the code looks clean with mypy (see conversation here).
I'll note that the code runs (at least until the login fails) so the libraries are properly installed.
Here is a sample:
Environment data
The text was updated successfully, but these errors were encountered: