Skip to content

Commit a4b18a8

Browse files
adrinjalalilhoestq
authored andcommitted
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 <[email protected]> Co-authored-by: Quentin Lhoest <[email protected]>
1 parent 2f65b70 commit a4b18a8

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/huggingface_hub/hf_api.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@
5858
# TODO: remove after deprecation period is over (v0.7)
5959
def _validate_repo_id_deprecation(repo_id, name, organization):
6060
"""Returns (name, organization) from the input."""
61+
if repo_id and not name and organization:
62+
# this means the user had passed name as positional, now mapped to
63+
# repo_id and is passing organization as well. This wouldn't be an
64+
# issue if they pass everything as kwarg. So we switch the parameters
65+
# here:
66+
repo_id, name = name, repo_id
67+
6168
if not (repo_id or name):
6269
raise ValueError(
6370
"No name provided. Please pass `repo_id` with a valid repository name."

tests/test_hf_api.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,14 @@ def test_validate_repo_id_deprecation():
227227
repo_id="repo_id", name="name", organization="organization"
228228
)
229229

230+
# regression test for
231+
# https://github.com/huggingface/huggingface_hub/issues/821
232+
with pytest.warns(FutureWarning, match="input arguments are deprecated"):
233+
name, org = _validate_repo_id_deprecation(
234+
repo_id="repo", name=None, organization="org"
235+
)
236+
assert name == "repo" and org == "org"
237+
230238

231239
@retry_endpoint
232240
def test_name_org_deprecation_warning():

0 commit comments

Comments
 (0)