-
Notifications
You must be signed in to change notification settings - Fork 581
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
Add autocomplete + tests + type checking #1041
Conversation
The documentation is not available anymore as the PR was closed or merged. |
Codecov Report
@@ Coverage Diff @@
## main #1041 +/- ##
==========================================
- Coverage 83.69% 83.67% -0.02%
==========================================
Files 37 37
Lines 3919 3915 -4
==========================================
- Hits 3280 3276 -4
Misses 639 639
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding this, it should make life easier for everyone!
I like the automated completion but IMO it shouldn't be done via pytest but via make style
(will add the new lines in init) and make quality
(will check that the init is properly written).
Also very very very much not a fan of mypy. I would have personally written a custom script to do the same check, but to each their own.
@sgugger Out of curiosity, what would be the advantage of having a custom script instead of using mypy here ? Some import stuff is not always trivial so I thought relying Just to mention that in general, I am in favor of running |
In my experience, mypy is the one making the stupid mistakes as soon as you have some complex types ;-) |
@sgugger I made the requested change to have it in a separate folder For |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for iterating on this, LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, looks good to me! Also not super in favor of mypy
, but if it doesn't require any deep changes here it's fine for me to keep it as is. Let's just remember to stay reasonable when it comes to typing :)
Thanks @sgugger @LysandreJik for the reviews. I'm merging. |
Fix #1036.
This PR adds static imports in
huggingface_hub.__init__.py
file. This allows IDEs to have autocomplete capabilities when importing stuff from huggingface_hub:To allow this, explicit imports have to be made under the
if TYPE_CHECKING
section which means newly added modules/functions have to be duplicated in the file (once for lazy load, once for static part). Suggested by @sgugger in #1036 (comment). I didn't implement it exactly the same way astransformers
as we don't need the same level of detail/technicality.In order to mitigate discrepancies, I added a test that checks all modules are declared twice. When adding a new module in the lazy-loading part, one need to run the following command to generate the static part and then commit the changes:
Finally, this PR adds
mypy
type checking in the CI for the root__init__.py
file. This is to check that we don't have a module exposed that doesn't exist (we previously hadfrom .hf_api import login, logout
butlogin
andlogout
apparently doesn't exist anymore).EDIT: also added a part in the test to ensure
_SUBMOD_ATTRS
definition is alphabetically ordered and rewrite it if it's not the case. Doesn't change much things but I tend to prefer (easier to read it/easier to look for something in it).