-
Notifications
You must be signed in to change notification settings - Fork 764
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
'reportMissingModuleSource' warning for requests.packages.* #597
Comments
I can confirm the same issue in this environment:
The command |
@trallnag Hi, thank you for the reporting. this is happening since those modules are created dynamically. requests\packages.py looks like this import sys
# This code exists for backwards compatibility reasons.
# I don't like it either. Just look the other way. :)
for package in ('urllib3', 'idna', 'chardet'):
locals()[package] = __import__(package)
# This traversal is apparently necessary such that the identities are
# preserved (requests.packages.urllib3.* is urllib3.*)
for mod in list(sys.modules):
if mod == package or mod.startswith(package + '.'):
sys.modules['requests.packages.' + mod] = sys.modules[mod]
# Kinda cool, though, right? but pyi in typeshed define these statically as expected. that's why you are seeing the warning (since typechecker can't verify py files exist for those modules in pyi) now, how to solve this. unfortunately, it is not easy for us to solve any dynamic behaviors until we have some kinds of plug in mechanism to inject some dynamic behaviors per libraries. that being said, if you are using default typecheckingmode (which is off), you can import urllib3 directly instead from urllib3.util import Retry since all actual library does is re-exporting urllib3 at runtime, it should work fine at runtime, and you should get auto-complete and etc at design/editing time. unfortunately, if you use other typecheckingmode, you might get type errors since symbol from typeshed pyi and urllib3 will be considered as different types. |
To further expand what said before, this works and won't throw another warning for
|
This comment has been minimized.
This comment has been minimized.
@alsitn I am not sure what you mean. |
I encounter this issue when developing a python extension modules (using Rust). As it is an extension created in another language, the source code is not available and hence I have that warning. I don't think the warning in this case (extension + already provided pyi) can help much as there is no way to fix (no source code). Can we have a work around for this specific scenario? |
If the extension is written in another language, the import should resolve to a binary library file (e.g. a ".so" file on Mac or Linux or a ".pyd" file on Windows). The warning is an indication that pylance would not resolve the import to either a python source (.py) file or a binary library file. Do you see such library files present? |
I'm getting this behavior while straight importing all of requests |
I am having this issue, too. |
I have this issue with random modules. Modules I've had this warning so far:
Pylance v2022.8.21. And yes the virtual environment is active. |
PyCharm's linting (and others) complain about this specific import as though it were an error, because the `requests.urllib3` module is created dynamically. But, we can just import `Retry` from `urillib3` directly, as per: microsoft/pylance-release#597 (comment)
same issue |
@hitrust can you open a new issue with a log as described in the troubleshooting guide? this issue is old one and won't be tracked. |
FWIW, I was able to get around this issue by using
And having vscode pylance look for the |
Bug
Pylance shows a
reportMissingModuleSource
on an valid import statement. And in addition the autocomplete and hinting works, it is just the warning that is wrong. Interestingly all other import statements that import stuff from the same library (requests
) work fine.Environment data
The only installed package in the environment is
requests
. I ensured that the venv is activated:Here is the pip list output:
How to recreate
You must have some kind of virtual environment tool, for example venv. I will use Pyenv and virutalenv in the example:
In shell:
Ensure tht correct env is activated.
Create a file on VS Code with following content
The text was updated successfully, but these errors were encountered: