From fcce57f56595fe872626a69cbe2f598641531a57 Mon Sep 17 00:00:00 2001 From: Ezeudoh Tochukwu Date: Fri, 15 Dec 2023 01:09:43 +0100 Subject: [PATCH 1/2] dropped black: replaced black with ruff and bumped up mypy and ruff version --- .github/workflows/test_full.yml | 2 -- Makefile | 6 ++---- ninja_extra/controllers/base.py | 2 +- ninja_extra/controllers/model/endpoints.py | 4 +--- ninja_extra/controllers/model/service.py | 2 +- ninja_extra/controllers/route/route_functions.py | 3 +-- ninja_extra/operation.py | 8 ++++++-- ninja_extra/permissions/base.py | 2 +- ninja_extra/router.py | 2 +- ninja_extra/shortcuts.py | 2 +- pyproject.toml | 7 +++---- 11 files changed, 18 insertions(+), 22 deletions(-) diff --git a/.github/workflows/test_full.yml b/.github/workflows/test_full.yml index 5fabb1c3..0c14c709 100644 --- a/.github/workflows/test_full.yml +++ b/.github/workflows/test_full.yml @@ -47,8 +47,6 @@ jobs: run: pip install flit - name: Install Dependencies run: flit install --symlink - - name: Black - run: black --check ninja_extra tests - name: Ruff Linting Check run: ruff check ninja_extra tests - name: mypy diff --git a/Makefile b/Makefile index 37f91056..3afb3629 100644 --- a/Makefile +++ b/Makefile @@ -9,19 +9,18 @@ clean: ## Removing cached python compiled files find . -name \*pyo | xargs rm -fv find . -name \*~ | xargs rm -fv find . -name __pycache__ | xargs rm -rfv + find . -name .ruff_cache | xargs rm -rfv install:clean ## Install dependencies flit install --deps develop --symlink pre-commit install -f lint:fmt ## Run code linters - make clean - black --check ninja_extra tests ruff check ninja_extra tests mypy ninja_extra fmt format:clean ## Run code formatters - black ninja_extra tests + ruff format ninja_extra tests ruff check --fix ninja_extra tests @@ -29,7 +28,6 @@ test:clean ## Run tests pytest . test-cov:clean ## Run tests with coverage - make clean pytest --cov=ninja_extra --cov-report term-missing tests doc-deploy:clean ## Run Deploy Documentation diff --git a/ninja_extra/controllers/base.py b/ninja_extra/controllers/base.py index a1d7146c..2a8b2670 100644 --- a/ninja_extra/controllers/base.py +++ b/ninja_extra/controllers/base.py @@ -66,7 +66,7 @@ def get_route_functions(cls: Type) -> Iterable[RouteFunction]: def get_all_controller_route_function( - controller: Union[Type["ControllerBase"], Type] + controller: Union[Type["ControllerBase"], Type], ) -> List[RouteFunction]: # pragma: no cover route_functions: List[RouteFunction] = [] for item in dir(controller): diff --git a/ninja_extra/controllers/model/endpoints.py b/ninja_extra/controllers/model/endpoints.py index c67dee48..2cfb828e 100644 --- a/ninja_extra/controllers/model/endpoints.py +++ b/ninja_extra/controllers/model/endpoints.py @@ -485,9 +485,7 @@ def list_items(self: "ModelControllerBase", **kwargs: t.Any) -> t.Any: list_items = route.get( working_path, response={ - status_code: pagination_response_schema[ - schema_out - ] # type:ignore[index] + status_code: pagination_response_schema[schema_out] # type:ignore[index] }, url_name=url_name, description=description, diff --git a/ninja_extra/controllers/model/service.py b/ninja_extra/controllers/model/service.py index 23a53eca..b810c0c7 100644 --- a/ninja_extra/controllers/model/service.py +++ b/ninja_extra/controllers/model/service.py @@ -34,7 +34,7 @@ def create(self, schema: PydanticModel, **kwargs: t.Any) -> t.Any: data.update(kwargs) try: - instance = self.model._default_manager.create(**data) + instance = self.model._default_manager.create(**data) # type: ignore[var-annotated] return instance except TypeError as tex: # pragma: no cover tb = traceback.format_exc() diff --git a/ninja_extra/controllers/route/route_functions.py b/ninja_extra/controllers/route/route_functions.py index 7ab5871a..509171e2 100644 --- a/ninja_extra/controllers/route/route_functions.py +++ b/ninja_extra/controllers/route/route_functions.py @@ -197,8 +197,7 @@ async def __call__( context = get_route_execution_context( request, temporal_response, - self.route.permissions - or _api_controller.permission_classes, # type:ignore[arg-type] + self.route.permissions or _api_controller.permission_classes, # type:ignore[arg-type] *args, **kwargs, ) diff --git a/ninja_extra/operation.py b/ninja_extra/operation.py index c8d92e9f..39c711d7 100644 --- a/ninja_extra/operation.py +++ b/ninja_extra/operation.py @@ -291,14 +291,18 @@ async def run(self, request: HttpRequest, **kw: Any) -> HttpResponseBase: # typ values = await self._get_values(request, kw, temporal_response) # type: ignore ctx.kwargs.update(values) result = await self.view_func(request, **values) - _processed_results = await self._result_to_response(request, result, temporal_response) # type: ignore + _processed_results = await self._result_to_response( + request, result, temporal_response + ) # type: ignore return cast(HttpResponseBase, _processed_results) except Exception as e: return self.api.on_exception(request, e) class PathView(NinjaPathView): - async def _async_view(self, request: HttpRequest, *args, **kwargs) -> HttpResponseBase: # type: ignore + async def _async_view( # type: ignore + self, request: HttpRequest, *args, **kwargs + ) -> HttpResponseBase: return await super(PathView, self)._async_view(request, *args, **kwargs) def _sync_view(self, request: HttpRequest, *args, **kwargs) -> HttpResponseBase: # type: ignore diff --git a/ninja_extra/permissions/base.py b/ninja_extra/permissions/base.py index e67bcfc4..da7f3be1 100644 --- a/ninja_extra/permissions/base.py +++ b/ninja_extra/permissions/base.py @@ -42,7 +42,7 @@ def __ror__( # type:ignore[misc] return OperandHolder(OR, other, self) def __invert__( # type:ignore[misc] - self: Union[Type["BasePermission"], "BasePermission"] + self: Union[Type["BasePermission"], "BasePermission"], ) -> "SingleOperandHolder[NOT]": return SingleOperandHolder(NOT, self) diff --git a/ninja_extra/router.py b/ninja_extra/router.py index 790ef7cf..a72dbd7f 100644 --- a/ninja_extra/router.py +++ b/ninja_extra/router.py @@ -34,7 +34,7 @@ def add_api_operation( exclude_none: bool = False, url_name: Optional[str] = None, include_in_schema: bool = True, - openapi_extra: Optional[Dict[str, Any]] = None + openapi_extra: Optional[Dict[str, Any]] = None, ) -> None: if path not in self.path_operations: path_view = PathView() diff --git a/ninja_extra/shortcuts.py b/ninja_extra/shortcuts.py index 7e6ffa77..0f60bca0 100644 --- a/ninja_extra/shortcuts.py +++ b/ninja_extra/shortcuts.py @@ -36,7 +36,7 @@ def get_object_or_exception( klass: Union[Type[Model], QuerySet], error_message: str = None, exception: Type[APIException] = NotFound, - **kwargs: Any + **kwargs: Any, ) -> Any: queryset = _get_queryset(klass) _validate_queryset(klass, queryset) diff --git a/pyproject.toml b/pyproject.toml index f9e6bc1d..bbf998d8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -58,10 +58,9 @@ test = [ "pytest", "pytest-cov", "pytest-django", - "pytest-asyncio", - "black ==23.10.1", - "mypy == 1.6.1", - "ruff ==0.1.4", + "pytest-asyncio==0.20.3", + "mypy == 1.7.1", + "ruff ==0.1.7", "ninja-schema>=0.13.4", "django-stubs", ] From 44098d2607d5a9a7f0735f94815ac01f3dd4b325 Mon Sep 17 00:00:00 2001 From: Ezeudoh Tochukwu Date: Fri, 15 Dec 2023 01:12:26 +0100 Subject: [PATCH 2/2] mypy fix --- ninja_extra/controllers/model/service.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ninja_extra/controllers/model/service.py b/ninja_extra/controllers/model/service.py index b810c0c7..23a53eca 100644 --- a/ninja_extra/controllers/model/service.py +++ b/ninja_extra/controllers/model/service.py @@ -34,7 +34,7 @@ def create(self, schema: PydanticModel, **kwargs: t.Any) -> t.Any: data.update(kwargs) try: - instance = self.model._default_manager.create(**data) # type: ignore[var-annotated] + instance = self.model._default_manager.create(**data) return instance except TypeError as tex: # pragma: no cover tb = traceback.format_exc()