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

FIX don't raise if name/organizaiton are passed postionally #822

Merged
merged 2 commits into from
Apr 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/huggingface_hub/hf_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@
# TODO: remove after deprecation period is over (v0.7)
def _validate_repo_id_deprecation(repo_id, name, organization):
"""Returns (name, organization) from the input."""
if repo_id and not name and organization:
# this means the user had passed name as positional, now mapped to
# repo_id and is passing organization as well. This wouldn't be an
# issue if they pass everything as kwarg. So we switch the parameters
# here:
repo_id, name = name, repo_id

if not (repo_id or name):
raise ValueError(
"No name provided. Please pass `repo_id` with a valid repository name."
Expand Down
8 changes: 8 additions & 0 deletions tests/test_hf_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,14 @@ def test_validate_repo_id_deprecation():
repo_id="repo_id", name="name", organization="organization"
)

# regression test for
# https://github.com/huggingface/huggingface_hub/issues/821
with pytest.warns(FutureWarning, match="input arguments are deprecated"):
name, org = _validate_repo_id_deprecation(
repo_id="repo", name=None, organization="org"
)
assert name == "repo" and org == "org"


@retry_endpoint
def test_name_org_deprecation_warning():
Expand Down