-
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
In the absence of stub files, auto-import should use better heuristics for picking preferred import path #222
Comments
now we handle this situation. for import alias (re-exported by stub files), we only show one that is the shortest path (smallest ".") in completion. |
This issue has been fixed in version 2020.9.0, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/master/CHANGELOG.md#202090-3-september-2020 |
Hey all! Thanks for this. 🚀 (And as I'm writing this on Dec 25, Merry Christmas/happy holidays to you all! 🎄 🤶 ) I recently released a new version of FastAPI with support for This was all after some email conversations with @erictraut finding the best ways to support type analysis, and after reading the guidelines in https://github.com/microsoft/pyright/blob/master/docs/typed-libraries.md Now, when I'm on a block like: from fastapi import ...and I trigger autocompletion there, Pylance/Pyright now can correctly detect that there are symbols available to import from the top level, like from fastapi import Query That's great! 🎉 👏 But then when using auto-import, it is not behaving as I would imagine. With a snippet like: from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def main(name: str = Query()):
pass ...if I trigger autocompletion/auto-import for I would expect it to suggest: from fastapi import Query Environment data
I imagine this is the right place to comment about this, but let me know if it should be in microsoft/pyright#922 or if I should create a new issue. Thanks! 🍰 ☕ |
Thanks @tiangolo for the issue. I think this one is different from the one that kicked off this thread. Could you please open a new issue for pylance-release? I just reviewed the latest version of |
Thanks for the speedy reply and feedback @erictraut ! 🤓 I just created a new issue here: #774 |
This suggestion comes from @tiangolo and is copied from microsoft/pyright#922.
The auto-import feature is not as smart as it could be about choosing the best import path for a symbol. With stub files, a library author can (but doesn't need to) specify a single export point for a symbol. For libraries that are missing stub files, a symbol is often imported and then re-exported by many submodules.
The auto-import feature should generally choose the shortest import path — i.e. the highest-level module that re-exports it.
The text was updated successfully, but these errors were encountered: