-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Ignore specific libraries when useLibraryCodeForTypes = true #945
Comments
My recommendation is that if you are using Pylance/Pyright for type checking, |
I'm going to leave this request open for now but mark it "blocked". It relates to some discussions we're having about support for type annotations within library "py" files, and I need to wait for those discussions to conclude before recommending a solution to the problem you've described. We're unlikely to implement the feature that you have described here, but there are other ways we could address the problem. |
@tekumara, I thought of a workaround that effectively provides the feature you asked for. You can define a local stub file for the libraries whose types you don't want to be used. Create a "typings" or "stubs" folder within your project. For each package you want to exclude from "useLibraryCodeForTypes", create a subfolder with the name of the package, add a
Pyright will then use the stub instead of the library code, and it will treat all symbols in that module as "Any" for the purpose of type checking. |
Please refer to #1003. I'm going to close this issue in favor of that one. |
This breaks coloring on imports from the Before (no custom After (custom This fix does get rid of other (most?) error detection issues with pyright, but it is a pretty annoying tradeoff to have to make. Might just go with sqlalchemy-stubs and make the jump to mypy for now :\ |
Enabling
"useLibraryCodeForTypes": true
will cause pyright to use/infer type information from.py
files.This can be helpful for third-party libraries that lack stubs. In general
"useLibraryCodeForTypes": true
is useful, and is the default for Pylance.However, the precision and completeness of inferred types varies between third-party libraries that lack stubs. For example, pytoml uses context managers and exceptions to control flow, and so inferred signatures have the return type
NoReturn
. Ideally pytoml would have stubs with the correct return types. Given it doesn't, the options are to disableuseLibraryCodeForTypes
(and lose its benefits for other libraries) or add# type: ignore
everywhere its functions are used.There are other libraries that have similar problems. Given the lack of stubs, and the varying quality of inference across libraries, would it be possible instead to selectively ignore specific libraries? Then
useLibraryCodeForTypes
and its benefits could still be had for most libraries.The text was updated successfully, but these errors were encountered: