diff --git a/modeltranslation/_typing.py b/modeltranslation/_typing.py index d884706f..d955ca3c 100644 --- a/modeltranslation/_typing.py +++ b/modeltranslation/_typing.py @@ -37,5 +37,4 @@ def class_getitem(cls: type, key: str | type | TypeVar): return cls for cls in classes: - if not hasattr(cls, "__class_getitem__"): - cls.__class_getitem__ = classmethod(class_getitem) # type: ignore[attr-defined] + cls.__class_getitem__ = classmethod(class_getitem) # type: ignore[attr-defined] diff --git a/modeltranslation/tests/settings.py b/modeltranslation/tests/settings.py index c408918b..5a617579 100644 --- a/modeltranslation/tests/settings.py +++ b/modeltranslation/tests/settings.py @@ -2,9 +2,11 @@ import warnings import django_stubs_ext +from modeltranslation._typing import monkeypatch warnings.simplefilter("always", DeprecationWarning) django_stubs_ext.monkeypatch() +monkeypatch() def _get_database_config(): diff --git a/modeltranslation/tests/tests.py b/modeltranslation/tests/tests.py index 00ae98e4..de5b46f5 100644 --- a/modeltranslation/tests/tests.py +++ b/modeltranslation/tests/tests.py @@ -2912,11 +2912,13 @@ class ProxyTestModelAdmin(admin.TranslationAdmin): assert tuple(ma.get_form(request, self.test_obj).base_fields.keys()) == tuple(fields) def test_class_attribute_access_raises_type_error(self): + # Test for django-cms compatibility + # https://github.com/django-cms/django-cms/issues/7948 class TestModelAdmin(admin.TranslationAdmin[models.TestModel]): allow_children = True with pytest.raises(KeyError): - TestModelAdmin["allow_children"] # type: ignore + TestModelAdmin["allow_children"] class ThirdPartyAppIntegrationTest(ModeltranslationTestBase):