From cb0c2818f1a28a6942681564cdacdb86ebe435b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20M=C3=B6ller?= Date: Wed, 19 Jun 2024 16:56:17 +0200 Subject: [PATCH 1/2] chore: bump werkzeug to >=3.0.3 Werkzeug 3.0.3 contains a fix for [1], so by requiring at least 3.0.3, we can remove unnecessary 'type: ignore' comments from the http adapter. [1]: https://github.com/pallets/werkzeug/issues/2836 --- requirements.txt | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 8335659a0..e087cdd18 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,7 +4,7 @@ python-dateutil>=2.8,<3.0 types-python-dateutil pyecma376-2>=0.2.4 urllib3>=1.26,<2.0 -Werkzeug~=3.0 +Werkzeug>=3.0.3,<4 schemathesis~=3.7 hypothesis~=6.13 lxml-stubs~=0.5.1 diff --git a/setup.py b/setup.py index cb1d0349c..1e0c43484 100755 --- a/setup.py +++ b/setup.py @@ -44,6 +44,6 @@ 'lxml>=4.2,<5', 'urllib3>=1.26,<2.0', 'pyecma376-2>=0.2.4', - 'Werkzeug~=3.0' + 'Werkzeug>=3.0.3,<4' ] ) From 5191fef64b535c9b721fd8e0308227971b05f4ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20M=C3=B6ller?= Date: Wed, 19 Jun 2024 17:03:01 +0200 Subject: [PATCH 2/2] adapter.http: improve type hints Remove 'type: ignore' comments now that we require werkzeug >=3.0.3 [1]. Furthermore, fix the type hint of `WSGIApp._get_slice()` and make two other 'type: ignore' comments more explicit. [1]: https://github.com/pallets/werkzeug/issues/2836 --- basyx/aas/adapter/http.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/basyx/aas/adapter/http.py b/basyx/aas/adapter/http.py index 10a37197e..3cc2dfe9b 100644 --- a/basyx/aas/adapter/http.py +++ b/basyx/aas/adapter/http.py @@ -5,10 +5,6 @@ # # SPDX-License-Identifier: MIT -# TODO: remove this once the werkzeug type annotations have been fixed -# https://github.com/pallets/werkzeug/issues/2836 -# mypy: disable-error-code="arg-type" - import abc import base64 import binascii @@ -18,7 +14,7 @@ import json import itertools -from lxml import etree # type: ignore +from lxml import etree import werkzeug.exceptions import werkzeug.routing import werkzeug.urls @@ -629,7 +625,7 @@ def _get_submodel_reference(cls, aas: model.AssetAdministrationShell, submodel_i raise NotFound(f"The AAS {aas!r} doesn't have a submodel reference to {submodel_id!r}!") @classmethod - def _get_slice(cls, request: Request, iterator: Iterator[T]) -> Tuple[Iterator[T], int]: + def _get_slice(cls, request: Request, iterator: Iterable[T]) -> Tuple[Iterator[T], int]: limit_str = request.args.get('limit', default="10") cursor_str = request.args.get('cursor', default="0") try: @@ -701,9 +697,7 @@ def handle_request(self, request: Request): endpoint, values = map_adapter.match() if endpoint is None: raise werkzeug.exceptions.NotImplemented("This route is not yet implemented.") - # TODO: remove this 'type: ignore' comment once the werkzeug type annotations have been fixed - # https://github.com/pallets/werkzeug/issues/2836 - return endpoint(request, values, map_adapter=map_adapter) # type: ignore[operator] + return endpoint(request, values, map_adapter=map_adapter) # any raised error that leaves this function will cause a 500 internal server error # so catch raised http exceptions and return them except werkzeug.exceptions.NotAcceptable as e: @@ -951,7 +945,8 @@ def post_submodel_submodel_elements_id_short_path(self, request: Request, url_ar raise BadRequest(f"{parent!r} is not a namespace, can't add child submodel element!") # TODO: remove the following type: ignore comment when mypy supports abstract types for Type[T] # see https://github.com/python/mypy/issues/5374 - new_submodel_element = HTTPApiDecoder.request_body(request, model.SubmodelElement, # type: ignore + new_submodel_element = HTTPApiDecoder.request_body(request, + model.SubmodelElement, # type: ignore[type-abstract] is_stripped_request(request)) try: parent.add_referable(new_submodel_element) @@ -971,7 +966,8 @@ def put_submodel_submodel_elements_id_short_path(self, request: Request, url_arg submodel_element = self._get_submodel_submodel_elements_id_short_path(url_args) # TODO: remove the following type: ignore comment when mypy supports abstract types for Type[T] # see https://github.com/python/mypy/issues/5374 - new_submodel_element = HTTPApiDecoder.request_body(request, model.SubmodelElement, # type: ignore + new_submodel_element = HTTPApiDecoder.request_body(request, + model.SubmodelElement, # type: ignore[type-abstract] is_stripped_request(request)) submodel_element.update_from(new_submodel_element) submodel_element.commit()