Skip to content
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

Handle autocomplete in IDE #1036

Closed
Wauplin opened this issue Sep 6, 2022 · 2 comments · Fixed by #1041
Closed

Handle autocomplete in IDE #1036

Wauplin opened this issue Sep 6, 2022 · 2 comments · Fixed by #1041

Comments

@Wauplin
Copy link
Contributor

Wauplin commented Sep 6, 2022

At the moment, when importing from huggingface_hub root module, autocomplete in IDE doesn't work (both method name + arguments/docstring). This is due to the lazy-loading have in __init__.py. From a UX perspective, It would be good to make the autocomplete work properly.

from huggingface_hub import upload_file # <- lazy-loading but no autocomplete
from huggingface_hub.hf_api import upload_file # <- autocomplete but no lazy-loading

Tested in both vscode (+Python/Pylance extensions) and PyCharm.

Maybe a if TYPE_CHECKING with imports behind is enough to solve that.

(cc @LysandreJik who reported it to me)

Note: autocomplete works in transformers.

@LysandreJik
Copy link
Member

Adding a quick note that autocomplete + lazy loading can work in parallel as we have seen in transformers. Also cc @sgugger who has worked on that in transformers.

@sgugger
Copy link
Contributor

sgugger commented Sep 6, 2022

I do believe a TYPE_CHECKING block would be enough to solve that, we have one in Transformers for this purpose and I think this is the only big difference between the two kinds of lazy loading (we have a different implementation not relying on Python 3.7 in Transformers but that does the same thing as huggingface_hub as far as I could tell).

It becomes annoying to have to make sure the two blocks are synchronized, which is why I built a quality script in Transformers to check the two parts of an init contain the same object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants