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
API deprecate positional args in file_download and hf_api #745
Conversation
I'd think some of this shouldn't be kwargs-only, such as list_models and list_datasets, where we've introduced the |
When we make a new release we add release notes to https://github.com/huggingface/huggingface_hub/releases |
But how do we keep track of the changelog? To me it makes sense to have a place where each PR which changes a user facing section to add the relevant entry to the changelog. And it can then be also rendered in the documentation. |
I'm not sure where the CO2 filtering is @muellerzr . Could you please comment where it needs to change? |
@adrinjalali here: https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/hf_api.py#L672 And here:
|
My other concern with deprecating the positional arguments is making it harder for the user to know what to pass in. Part of the goal with all these functions is that users in an IDE can rely on tab-completion to know what to pass in, and what is available. (Which is why we have |
@muellerzr that parameter is the fourth argument. I don't think mimicking the REST API is important here, as people using the library won't necessary even know what the REST API looks like. So I would rather keep that as kwonly. |
When we decided to do this in sklearn, we had the same concerns. But at the end testing with IDEs we didn't see any major issues and the benefits outweighed the downsides. |
@adrinjalali could you outline the benefits vs the downsides for me? It'd help a lot with getting me comfortable with the idea 😄 (I can quickly think of a few including code maintainability as the API changes, since everything is a kwarg. But say for instance a kwarg to be passed changed. How would you make sure there isn't technical debt with the docstring and write a check for it outside of just good reviewers) |
So here's the SLEP (scikit-learn enhancement proposal) discussing the exact same issue: https://scikit-learn-enhancement-proposals.readthedocs.io/en/latest/slep009/proposal.html with links to original discussions. I think almost everything applies here too.
We can have docstring common tests which make sure every PR updates the docstrings of the methods/functions/classes they're changing as well:
(note that those tests are numpydoc specific, we'd need to write them for the google style docs) |
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.
I'm enthusiastic about the change from positional + keyword argument to forced keyword arguments. I'm a bit less enthusiastic about converting all arguments (including current positional-only arguments) to forced-keyword arguments.
For example, I think this should be acceptable:
from huggingface_hub import hf_hub_url
hf_hub_url('bert-base-cased', 'config.json')
Whereas this should not:
from huggingface_hub import hf_hub_url
- hf_hub_url('bert-base-cased', 'config.json', 'subfolder') # unclear
+ hf_hub_url('bert-base-cased', 'config.json', subfolder='subfolder') # clearer
I agree. Changed a few of them, but in the |
I can't run the
|
Could you try running it with |
Thanks, that fixes the issue. |
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! I've left a few comments, my remark regarding the positional vs keyword arguments wasn't only linked to hf_hub_url
but to all positional/keyword arguments that you have changed.
It's especially the case for create_repo
and delete_repo
, for example.
@@ -229,6 +234,7 @@ def _raise_if_offline_mode_is_enabled(msg: Optional[str] = None): | |||
|
|||
|
|||
def _request_with_retry( |
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.
Should this have a @_deprecate_positional_args
decorator?
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.
Since this is private API, I don't think it needs to follow our deprecation policy here. Private API can change at any time w/o any guarantees for the user.
src/huggingface_hub/hf_api.py
Outdated
@_deprecate_positional_args | ||
def list_repo_files( | ||
self, | ||
*, | ||
repo_id: str, |
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.
There are a few others below I can't do with suggestions, so will stop there for suggestions on this kind of reordering.
Regarding the changelog question: for releases we use the "Auto-generate release notes" button for releases: Then we manually add a description/example of the commits that had an impact on the user-facing API. See v0.4.0 for example. |
I'd wait for #733 to be merged before fixing this one. |
@LysandreJik I think I've addressed your comments. Let me know if there are other places where you'd like to see positional args which are not included now. |
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.
Looks great! Only left a few comments, and @osanseviero I'd be happy for you to take a second look at the ones I tagged you on as I'm hovering between two possibilities.
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.
Looks nice! Thank you! Approving pending @LysandreJik approval. I left some minor comments
] | ||
args_msg = ", ".join(args_msg) | ||
warnings.warn( | ||
f"Pass {args_msg} as keyword args. From version " |
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.
Nit
get_full_repo_name("repo_name")
will give warning
Pass model_id=repo_name as keyword args.
but expected would be
Pass model_id="repo_name" as keyword args.
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.
It can get quite complicated if we actually try to handle many different data types I think, but I single out string here then.
I think all comments should be addressed now. @LysandreJik please merge if you're happy with this. (The CI failure seems unrelated) |
Opened #785 for the failing CI. |
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.
Should be good to go for me! I'll let you merge in case you want to rebase/merge main
to see if all tests pass; otherwise, feel free to merge at your convenience. Thanks for working on it @adrinjalali!
Fixes #732
This PR deprecates passing positional args to most functions and methods in
file_download.py
andhf_api.py
.Things to discuss:
cc @julien-c @LysandreJik @osanseviero
Question: do we have a place to put changelog/release logs? How do we handle those now?