Skip to content

Commit

Permalink
fix: mypy check
Browse files Browse the repository at this point in the history
  • Loading branch information
Hongbin Huang authored and freemindcore committed Nov 22, 2023
1 parent 255fc91 commit e5ded07
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion easy/controller/auto_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
4 changes: 2 additions & 2 deletions easy/controller/meta_conf.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -24,7 +24,7 @@


class ModelOptions:
def __init__(self, options: Dict = None):
def __init__(self, options: Optional[object] = None):
"""
Configuration reader
"""
Expand Down
6 changes: 3 additions & 3 deletions easy/decorators.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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]]:
"""
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion easy/domain/orm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
5 changes: 3 additions & 2 deletions easy/exception.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.utils.translation import gettext_lazy as _
from ninja_extra import status
from ninja_extra.exceptions import APIException

Expand All @@ -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."
)
Expand All @@ -20,4 +21,4 @@ class APIAuthException(BaseAPIException):
"""

status_code = status.HTTP_401_UNAUTHORIZED
default_detail = "Unauthorized"
default_detail = _("Unauthorized")
4 changes: 2 additions & 2 deletions easy/permissions/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
8 changes: 4 additions & 4 deletions easy/testing/client.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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(""))
Expand All @@ -33,7 +33,7 @@ def request(
self,
method: str,
path: str,
data: Dict = {},
data: Optional[Dict] = None,
json: Any = None,
**request_params: Any,
) -> "NinjaResponse":
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit e5ded07

Please sign in to comment.