diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8fea904..db33b6e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -23,7 +23,7 @@ repos: args: [--allow-missing-credentials] - repo: https://github.com/psf/black - rev: 22.8.0 + rev: 23.10.1 hooks: - id: black diff --git a/easy/__init__.py b/easy/__init__.py index 9ec75cc..55c1888 100644 --- a/easy/__init__.py +++ b/easy/__init__.py @@ -1,6 +1,6 @@ """Django Easy API - Easy and Fast Django REST framework based on Django-ninja-extra""" -__version__ = "0.1.40" +__version__ = "0.2.0" from easy.main import EasyAPI diff --git a/easy/controller/auto_api.py b/easy/controller/auto_api.py index fd7d1d0..dd1d67b 100644 --- a/easy/controller/auto_api.py +++ b/easy/controller/auto_api.py @@ -58,7 +58,7 @@ def create_api_controller( }, ) - return api_controller( # type: ignore + return api_controller( f"/{app_name}/{model_name.lower()}", tags=[f"{model_name} {controller_name_prefix}API"], permissions=[permission_class], diff --git a/easy/controller/meta_conf.py b/easy/controller/meta_conf.py index d07d043..3902ea7 100644 --- a/easy/controller/meta_conf.py +++ b/easy/controller/meta_conf.py @@ -1,4 +1,4 @@ -from typing import Any, Dict, List, Optional, Type, Union +from typing import Any, List, Optional, Type, Union from django.db import models @@ -24,7 +24,7 @@ class ModelOptions: - def __init__(self, options: Dict = None): + def __init__(self, options: Optional[object] = None): """ Configuration reader """ diff --git a/easy/decorators.py b/easy/decorators.py index 23b0183..a56b06a 100644 --- a/easy/decorators.py +++ b/easy/decorators.py @@ -1,6 +1,6 @@ from functools import wraps from types import FunctionType -from typing import Any, Callable +from typing import Any, Callable, Optional from urllib.parse import urlparse from django.conf import settings @@ -11,7 +11,7 @@ def request_passes_test( test_func: Callable[[Any], Any], - login_url: str = None, + login_url: Optional[str] = None, redirect_field_name: str = REDIRECT_FIELD_NAME, ) -> Callable[[FunctionType], Callable[[HttpRequest, Any], Any]]: """ @@ -45,7 +45,7 @@ def _wrapped_view(request: HttpRequest, *args: Any, **kwargs: Any) -> Any: def docs_permission_required( - view_func: FunctionType = None, + view_func: Optional[FunctionType] = None, redirect_field_name: str = REDIRECT_FIELD_NAME, login_url: str = "admin:login", ) -> Any: diff --git a/easy/domain/orm.py b/easy/domain/orm.py index 2617f36..740e427 100644 --- a/easy/domain/orm.py +++ b/easy/domain/orm.py @@ -220,7 +220,7 @@ def serialize_many_relationship( return {} out = {} try: - for k, v in obj._prefetched_objects_cache.items(): # type: ignore + for k, v in obj._prefetched_objects_cache.items(): field_name = k if hasattr(obj, k) else k + "_set" if v: if self.get_model_join(obj): diff --git a/easy/exception.py b/easy/exception.py index f140f12..a842024 100644 --- a/easy/exception.py +++ b/easy/exception.py @@ -1,3 +1,4 @@ +from django.utils.translation import gettext_lazy as _ from ninja_extra import status from ninja_extra.exceptions import APIException @@ -8,7 +9,7 @@ class BaseAPIException(APIException): """ status_code = status.HTTP_500_INTERNAL_SERVER_ERROR - default_detail = ( + default_detail = _( "There is an unexpected error, please try again later, if the problem " "persists, please contact customer support team for further support." ) @@ -20,4 +21,4 @@ class APIAuthException(BaseAPIException): """ status_code = status.HTTP_401_UNAUTHORIZED - default_detail = "Unauthorized" + default_detail = _("Unauthorized") diff --git a/easy/permissions/base.py b/easy/permissions/base.py index 0c59a7f..76cb28d 100644 --- a/easy/permissions/base.py +++ b/easy/permissions/base.py @@ -21,7 +21,7 @@ def has_permission( """ has_perm: bool = True if hasattr(controller, "service"): - has_perm = controller.service.check_permission(request, controller) # type: ignore + has_perm = controller.service.check_permission(request, controller) return has_perm def has_object_permission( @@ -32,7 +32,7 @@ def has_object_permission( """ has_perm: bool = True if hasattr(controller, "service"): - has_perm = controller.service.check_object_permission( # type: ignore + has_perm = controller.service.check_object_permission( request, controller, obj ) return has_perm diff --git a/easy/testing/client.py b/easy/testing/client.py index 4c93613..3ad0d15 100644 --- a/easy/testing/client.py +++ b/easy/testing/client.py @@ -1,5 +1,5 @@ from json import dumps as json_dumps -from typing import Any, Callable, Dict, List, Sequence, Type, Union, cast +from typing import Any, Callable, Dict, List, Optional, Sequence, Type, Union, cast from unittest.mock import Mock from urllib.parse import urlencode @@ -22,7 +22,7 @@ def __init__( ) -> None: if hasattr(router_or_app, "get_api_controller"): api = api_cls(auth=auth) - controller_ninja_api_controller = router_or_app.get_api_controller() # type: ignore + controller_ninja_api_controller = router_or_app.get_api_controller() assert controller_ninja_api_controller controller_ninja_api_controller.set_api_instance(api) self._urls_cache = list(controller_ninja_api_controller.urls_paths("")) @@ -33,7 +33,7 @@ def request( self, method: str, path: str, - data: Dict = {}, + data: Optional[Dict] = None, json: Any = None, **request_params: Any, ) -> "NinjaResponse": @@ -43,7 +43,7 @@ def request( query = request_params.pop("query") url_encode = urlencode(query) path = f"{path}?{url_encode}" - func, request, kwargs = self._resolve(method, path, data, request_params) + func, request, kwargs = self._resolve(method, path, data, request_params) # type: ignore return self._call(func, request, kwargs) # type: ignore @property diff --git a/pyproject.toml b/pyproject.toml index 242661a..4cc0513 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -57,16 +57,16 @@ test = [ "pytest-cov", "pytest-django", "pytest-asyncio", - "black", + "black==23.10.1", + "mypy==1.6.1", "isort", - "injector == 0.19.0", + "injector>= 0.19.0", "flake8", - "mypy==0.931", "django-stubs", "factory-boy==3.2.1", "django_coverage_plugin", - "django-ninja-extra >= 0.16.0", - "django-ninja-jwt>=5.1.0", + "django-ninja-extra >= 0.20.0", + "django-ninja-jwt>=5.2.9", "Django >= 3.1", ] dev = [ diff --git a/setup.cfg b/setup.cfg index d12e57c..ff77453 100644 --- a/setup.cfg +++ b/setup.cfg @@ -82,6 +82,7 @@ warn_unused_ignores = True disallow_untyped_defs = True check_untyped_defs = True no_implicit_reexport = True +no_implicit_optional = False [mypy.plugins.django-stubs] django_settings_module = "tests.easy_app"