Skip to content

Commit bf0f208

Browse files
authored
Fix ReprMixin for python3.7 + test (#1380)
1 parent e3fa660 commit bf0f208

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/huggingface_hub/hf_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class ReprMixin:
9797
"""Mixin to create the __repr__ for a class"""
9898

9999
def __repr__(self):
100-
formatted_value = pprint.pformat(self.__dict__, width=119, compact=True, sort_dicts=False)
100+
formatted_value = pprint.pformat(self.__dict__, width=119, compact=True)
101101
if "\n" in formatted_value:
102102
return f"{self.__class__.__name__}: {{ \n{textwrap.indent(formatted_value, ' ')}\n}}"
103103
else:

tests/test_hf_api.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from functools import partial
2424
from io import BytesIO
2525
from pathlib import Path
26-
from typing import List, Union
26+
from typing import Any, Dict, List, Union
2727
from unittest.mock import Mock, patch
2828
from urllib.parse import quote
2929

@@ -57,6 +57,7 @@
5757
ModelSearchArguments,
5858
RepoFile,
5959
RepoUrl,
60+
ReprMixin,
6061
SpaceInfo,
6162
erase_from_credential_store,
6263
read_from_credential_store,
@@ -2736,3 +2737,15 @@ def test_duplicate_space_from_missing_repo(self) -> None:
27362737

27372738
with self.assertRaises(RepositoryNotFoundError):
27382739
self._api.duplicate_space(f"{OTHER_USER}/repo_that_does_not_exist")
2740+
2741+
2742+
class ReprMixinTest(unittest.TestCase):
2743+
def test_repr_mixin(self) -> None:
2744+
class MyClass(ReprMixin):
2745+
def __init__(self, **kwargs: Dict[str, Any]) -> None:
2746+
self.__dict__.update(kwargs)
2747+
2748+
self.assertEqual(
2749+
repr(MyClass(foo="foo", bar="bar")),
2750+
"MyClass: {'bar': 'bar', 'foo': 'foo'}", # keys are sorted
2751+
)

0 commit comments

Comments
 (0)