Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
last-partizan committed Sep 4, 2024
1 parent d420b6a commit 89c5109
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 3 additions & 3 deletions modeltranslation/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ def class_getitem(cls: type, key: str | type | TypeVar):
raise KeyError(f"Key '{key}' found as attribute, use getattr to access it.")
return cls

for class_ in classes:
if not hasattr(class_, "__class_getitem__"):
class_.__class_getitem__ = classmethod(class_getitem) # type: ignore[attr-defined]
for cls in classes:
if not hasattr(cls, "__class_getitem__"):
cls.__class_getitem__ = classmethod(class_getitem) # type: ignore[attr-defined]
7 changes: 7 additions & 0 deletions modeltranslation/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2911,6 +2911,13 @@ class ProxyTestModelAdmin(admin.TranslationAdmin):
assert tuple(ma.get_form(request).base_fields.keys()) == tuple(fields)
assert tuple(ma.get_form(request, self.test_obj).base_fields.keys()) == tuple(fields)

def test_class_attribute_access_raises_type_error(self):
class TestModelAdmin(admin.TranslationAdmin[models.TestModel]):
allow_children = True

with pytest.raises(KeyError):
TestModelAdmin["allow_children"] # type: ignore


class ThirdPartyAppIntegrationTest(ModeltranslationTestBase):
"""
Expand Down

0 comments on commit 89c5109

Please sign in to comment.