Skip to content

Commit

Permalink
Merge pull request #43 from rwth-iat/http_api/fix_type_ignore_comments
Browse files Browse the repository at this point in the history
adapter.http: remove and improve `type: ignore` comments
  • Loading branch information
Frosty2500 committed Jun 20, 2024
2 parents b0e1148 + 5191fef commit f57a640
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
18 changes: 7 additions & 11 deletions basyx/aas/adapter/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
]
)

0 comments on commit f57a640

Please sign in to comment.