Skip to content

Commit

Permalink
FIX don't raise if name/organizaiton are passed postionally (#822)
Browse files Browse the repository at this point in the history
* FIX don't raise if name/organizaiton are passed postionally

* Fix typo in comment

Co-authored-by: Quentin Lhoest <42851186+lhoestq@users.noreply.github.com>

Co-authored-by: Quentin Lhoest <42851186+lhoestq@users.noreply.github.com>
  • Loading branch information
2 people authored and LysandreJik committed Apr 6, 2022
1 parent 2f65b70 commit a4b18a8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
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

0 comments on commit a4b18a8

Please sign in to comment.