Skip to content

Commit 26d6ba2

Browse files
zrgts-heppner
authored andcommitted
Remove TODOs regarding Type[T] issue in mypy
The issue in mypy (python/mypy#5374) is solved
1 parent 1a5bcbc commit 26d6ba2

3 files changed

Lines changed: 8 additions & 28 deletions

File tree

‎sdk/basyx/aas/adapter/http.py‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -721,9 +721,7 @@ def handle_request(self, request: Request):
721721

722722
try:
723723
endpoint, values = map_adapter.match()
724-
# TODO: remove this 'type: ignore' comment once the werkzeug type annotations have been fixed
725-
# https://github.com/pallets/werkzeug/issues/2836
726-
return endpoint(request, values, response_t=response_t, map_adapter=map_adapter) # type: ignore[operator]
724+
return endpoint(request, values, response_t=response_t, map_adapter=map_adapter)
727725

728726
# any raised error that leaves this function will cause a 500 internal server error
729727
# so catch raised http exceptions and return them
@@ -954,10 +952,8 @@ def post_submodel_submodel_elements_id_short_path(self, request: Request, url_ar
954952
parent = self._get_submodel_or_nested_submodel_element(url_args)
955953
if not isinstance(parent, model.UniqueIdShortNamespace):
956954
raise BadRequest(f"{parent!r} is not a namespace, can't add child submodel element!")
957-
# TODO: remove the following type: ignore comment when mypy supports abstract types for Type[T]
958-
# see https://github.com/python/mypy/issues/5374
959955
new_submodel_element = HTTPApiDecoder.request_body(request,
960-
model.SubmodelElement, # type: ignore[type-abstract]
956+
model.SubmodelElement,
961957
is_stripped_request(request))
962958
try:
963959
parent.add_referable(new_submodel_element)
@@ -978,10 +974,8 @@ def put_submodel_submodel_elements_id_short_path(self, request: Request, url_arg
978974
response_t: Type[APIResponse],
979975
**_kwargs) -> Response:
980976
submodel_element = self._get_submodel_submodel_elements_id_short_path(url_args)
981-
# TODO: remove the following type: ignore comment when mypy supports abstract types for Type[T]
982-
# see https://github.com/python/mypy/issues/5374
983977
new_submodel_element = HTTPApiDecoder.request_body(request,
984-
model.SubmodelElement, # type: ignore[type-abstract]
978+
model.SubmodelElement,
985979
is_stripped_request(request))
986980
submodel_element.update_from(new_submodel_element)
987981
submodel_element.commit()

‎sdk/basyx/aas/adapter/json/json_deserialization.py‎

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -263,12 +263,10 @@ def _amend_abstract_attributes(cls, obj: object, dct: Dict[str, object]) -> None
263263
if 'embeddedDataSpecifications' in dct:
264264
for dspec in _get_ts(dct, 'embeddedDataSpecifications', list):
265265
obj.embedded_data_specifications.append(
266-
# TODO: remove the following type: ignore comment when mypy supports abstract types for Type[T]
267-
# see https://github.com/python/mypy/issues/5374
268266
model.EmbeddedDataSpecification(
269267
data_specification=cls._construct_reference(_get_ts(dspec, 'dataSpecification', dict)),
270268
data_specification_content=_get_ts(dspec, 'dataSpecificationContent',
271-
model.DataSpecificationContent) # type: ignore
269+
model.DataSpecificationContent)
272270
)
273271
)
274272
if isinstance(obj, model.HasExtension) and not cls.stripped:
@@ -370,9 +368,7 @@ def _construct_operation_variable(cls, dct: Dict[str, object]) -> model.Submodel
370368
Since we don't implement ``OperationVariable``, this constructor discards the wrapping ``OperationVariable``
371369
object and just returns the contained :class:`~basyx.aas.model.submodel.SubmodelElement`.
372370
"""
373-
# TODO: remove the following type: ignore comments when mypy supports abstract types for Type[T]
374-
# see https://github.com/python/mypy/issues/5374
375-
return _get_ts(dct, 'value', model.SubmodelElement) # type: ignore
371+
return _get_ts(dct, 'value', model.SubmodelElement)
376372

377373
@classmethod
378374
def _construct_lang_string_set(cls, lst: List[Dict[str, object]], object_class: Type[LSS]) -> LSS:
@@ -568,11 +564,9 @@ def _construct_capability(cls, dct: Dict[str, object], object_class=model.Capabi
568564
@classmethod
569565
def _construct_basic_event_element(cls, dct: Dict[str, object], object_class=model.BasicEventElement) \
570566
-> model.BasicEventElement:
571-
# TODO: remove the following type: ignore comments when mypy supports abstract types for Type[T]
572-
# see https://github.com/python/mypy/issues/5374
573567
ret = object_class(id_short=None,
574568
observed=cls._construct_model_reference(_get_ts(dct, 'observed', dict),
575-
model.Referable), # type: ignore
569+
model.Referable),
576570
direction=DIRECTION_INVERSE[_get_ts(dct, "direction", str)],
577571
state=STATE_OF_EVENT_INVERSE[_get_ts(dct, "state", str)])
578572
cls._amend_abstract_attributes(ret, dct)
@@ -613,8 +607,6 @@ def _construct_operation(cls, dct: Dict[str, object], object_class=model.Operati
613607
@classmethod
614608
def _construct_relationship_element(
615609
cls, dct: Dict[str, object], object_class=model.RelationshipElement) -> model.RelationshipElement:
616-
# TODO: remove the following type: ignore comments when mypy supports abstract types for Type[T]
617-
# see https://github.com/python/mypy/issues/5374
618610
ret = object_class(id_short=None,
619611
first=cls._construct_reference(_get_ts(dct, 'first', dict)),
620612
second=cls._construct_reference(_get_ts(dct, 'second', dict)))
@@ -625,8 +617,6 @@ def _construct_relationship_element(
625617
def _construct_annotated_relationship_element(
626618
cls, dct: Dict[str, object], object_class=model.AnnotatedRelationshipElement)\
627619
-> model.AnnotatedRelationshipElement:
628-
# TODO: remove the following type: ignore comments when mypy supports abstract types for Type[T]
629-
# see https://github.com/python/mypy/issues/5374
630620
ret = object_class(
631621
id_short=None,
632622
first=cls._construct_reference(_get_ts(dct, 'first', dict)),

‎sdk/basyx/aas/adapter/xml/xml_deserialization.py‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -534,9 +534,7 @@ def _construct_referable_reference(cls, element: etree._Element, **kwargs: Any)
534534
"""
535535
Helper function. Doesn't support the object_class parameter. Overwrite construct_aas_reference instead.
536536
"""
537-
# TODO: remove the following type: ignore comments when mypy supports abstract types for Type[T]
538-
# see https://github.com/python/mypy/issues/5374
539-
return cls.construct_model_reference_expect_type(element, model.Referable, **kwargs) # type: ignore
537+
return cls.construct_model_reference_expect_type(element, model.Referable, **kwargs)
540538

541539
@classmethod
542540
def _construct_operation_variable(cls, element: etree._Element, **kwargs: Any) -> model.SubmodelElement:
@@ -590,9 +588,7 @@ def construct_model_reference(cls, element: etree._Element, object_class=model.M
590588
"""
591589
_expect_reference_type(element, model.ModelReference)
592590
keys = cls._construct_key_tuple(element)
593-
# TODO: remove the following type: ignore comments when mypy supports abstract types for Type[T]
594-
# see https://github.com/python/mypy/issues/5374
595-
type_: Type[model.Referable] = model.Referable # type: ignore
591+
type_: Type[model.Referable] = model.Referable
596592
if len(keys) > 0:
597593
type_ = KEY_TYPES_CLASSES_INVERSE.get(keys[-1].type, model.Referable) # type: ignore
598594
return object_class(keys, type_, _failsafe_construct(element.find(NS_AAS + "referredSemanticId"),

0 commit comments

Comments
 (0)