Skip to content

Commit

Permalink
fix: Fix django-cms compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
last-partizan committed Sep 4, 2024
1 parent 04d150b commit d420b6a
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions modeltranslation/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,13 @@ def monkeypatch() -> None:
BaseModelAdmin,
]

def class_getitem(cls: type, key: str | type | TypeVar):
if isinstance(key, str) and hasattr(cls, key):
# Fix django-cms compatibility:
# https://github.com/django-cms/django-cms/issues/7948
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( # type: ignore[attr-defined]
lambda cls, *args, **kwargs: cls
)
class_.__class_getitem__ = classmethod(class_getitem) # type: ignore[attr-defined]

0 comments on commit d420b6a

Please sign in to comment.