From a4b18a8093ddccdf2e064babba2fc15d89a23219 Mon Sep 17 00:00:00 2001 From: Adrin Jalali Date: Wed, 6 Apr 2022 13:58:06 +0200 Subject: [PATCH] FIX don't raise if name/organizaiton are passed postionally (#822) * 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> --- src/huggingface_hub/hf_api.py | 7 +++++++ tests/test_hf_api.py | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/src/huggingface_hub/hf_api.py b/src/huggingface_hub/hf_api.py index 2e0f9bec59..8c2be0fb55 100644 --- a/src/huggingface_hub/hf_api.py +++ b/src/huggingface_hub/hf_api.py @@ -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." diff --git a/tests/test_hf_api.py b/tests/test_hf_api.py index c76863e72f..beccebbe79 100644 --- a/tests/test_hf_api.py +++ b/tests/test_hf_api.py @@ -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():