diff --git a/openedx/core/types/__init__.py b/openedx/core/types/__init__.py index 15e03db2ac..a4a4dc7e77 100644 --- a/openedx/core/types/__init__.py +++ b/openedx/core/types/__init__.py @@ -1,5 +1,5 @@ """ Add here typing utilities API functions and classes. """ -from .admin import admin_display +from django.contrib.admin import display as admin_display from .user import User diff --git a/openedx/core/types/admin.py b/openedx/core/types/admin.py deleted file mode 100644 index b6ff8c16d9..0000000000 --- a/openedx/core/types/admin.py +++ /dev/null @@ -1,57 +0,0 @@ -""" -Typing utilities for the admin sites. -""" -import warnings - -from typing import Any, Callable, Optional, Protocol - - -class AdminMethod(Protocol): - """ - Duck-type definition of a callable admin method. - - See: - https://github.com/python/mypy/issues/2087#issuecomment-462726600 - https://mypy.readthedocs.io/en/stable/protocols.html - https://www.python.org/dev/peps/pep-0544/ - """ - - short_description: str - boolean: bool - - -def _admin_display( - boolean: Optional[bool] = None, description: Optional[str] = None -) -> Callable[[Any], AdminMethod]: - """ - Decorator for functions that need to be annotated with attributes from AdminMethod. - - This method and the above AdminMethod class will no longer be necessary in Django 3.2, - when `admin.display` is introduced: - https://docs.djangoproject.com/en/3.2/ref/contrib/admin/#django.contrib.admin.display - """ - - def decorator(func: Any) -> AdminMethod: - if boolean is not None: - func.boolean = boolean - if description is not None: - func.short_description = description - return func - - return decorator - - -try: - import django.contrib.admin - - admin_display = django.contrib.admin.display - if _admin_display or AdminMethod: - warnings.warn( - ( - "Django 3.2+ available: the _admin_display method and the AdminMethod" - "class should be removed from openedx.core.types" - ), - DeprecationWarning, - ) -except AttributeError: - admin_display = _admin_display diff --git a/requirements/edx/development.txt b/requirements/edx/development.txt index bc416905ba..4af8c4bc46 100644 --- a/requirements/edx/development.txt +++ b/requirements/edx/development.txt @@ -960,7 +960,7 @@ multidict==6.0.2 # -r requirements/edx/testing.txt # aiohttp # yarl -mypy==0.982 +mypy==0.991 # via -r requirements/edx/development.in mypy-extensions==0.4.3 # via mypy