From 9e884908544fcd3568ff9334b61fc3ed7590c76c Mon Sep 17 00:00:00 2001 From: Julian Vogel Date: Thu, 28 Nov 2024 14:53:13 +0100 Subject: [PATCH] fix: support python 3.10, 3.11 --- src/pdf2aas/evaluation/aas.py | 4 ++-- src/pdf2aas/generator/aas_technical_data_submodel.py | 6 +++--- src/pdf2aas/model/property.py | 8 ++++---- tests/test_generator.py | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/pdf2aas/evaluation/aas.py b/src/pdf2aas/evaluation/aas.py index 19086a9..17ba902 100644 --- a/src/pdf2aas/evaluation/aas.py +++ b/src/pdf2aas/evaluation/aas.py @@ -1,10 +1,10 @@ """Classes for the evaluation of pdf2aas conversion using Asset Administration Shells as input.""" -import datetime import json import logging import re import shutil +from datetime import datetime, timezone from pathlib import Path from typing import ClassVar @@ -222,7 +222,7 @@ def run_extraction(self) -> Path | None: """ run_path = None if self.eval_path: - run_path = self.eval_path / datetime.datetime.now(tz=datetime.UTC).strftime( + run_path = self.eval_path / datetime.now(tz=timezone.utc).strftime( "%Y-%m-%d_%H-%M-%S", ) run_path.mkdir(parents=True, exist_ok=True) diff --git a/src/pdf2aas/generator/aas_technical_data_submodel.py b/src/pdf2aas/generator/aas_technical_data_submodel.py index 84041dc..d1785ee 100644 --- a/src/pdf2aas/generator/aas_technical_data_submodel.py +++ b/src/pdf2aas/generator/aas_technical_data_submodel.py @@ -1,10 +1,10 @@ """Generator for Technical Data Submodels of Asset Administration Shells.""" -import datetime import json import logging import re import uuid +from datetime import datetime, timezone from typing import ClassVar from basyx.aas import model @@ -174,7 +174,7 @@ def _create_submodel_template(self) -> model.Submodel: model.Property( id_short="ValidDate", value_type=model.datatypes.Date, - value=datetime.datetime.now(tz=datetime.UTC).date(), + value=datetime.now(tz=timezone.utc).date(), category="PARAMETER", semantic_id=self._create_semantic_id( "https://admin-shell.io/ZVEI/TechnicalData/ValidDate/1/1", @@ -403,7 +403,7 @@ def _create_aas_property_smc( None, ), ) - except AASConstraintViolation as error: + except AASConstraintViolation as error: # noqa: PERF203 logger.warning( "Couldn't add %s item to property %s: %s", type(value), diff --git a/src/pdf2aas/model/property.py b/src/pdf2aas/model/property.py index d5946b8..267b1ca 100644 --- a/src/pdf2aas/model/property.py +++ b/src/pdf2aas/model/property.py @@ -3,7 +3,7 @@ import re import uuid from dataclasses import dataclass, field -from typing import Any, Self +from typing import Any from .property_definition import PropertyDefinition @@ -109,8 +109,8 @@ def to_legacy_dict(self) -> dict[str, str | None]: "name": self.definition_name, } - @classmethod - def from_dict(cls, property_dict: dict) -> Self: + @staticmethod + def from_dict(property_dict: dict) -> "Property": """Parse a Property from a dictionary.""" label = property_dict.get("property") if label is None: @@ -118,7 +118,7 @@ def from_dict(cls, property_dict: dict) -> Self: if label is None: label = "" - return cls( + return Property( label, property_dict.get("value"), property_dict.get("unit"), diff --git a/tests/test_generator.py b/tests/test_generator.py index 2ba7cd3..4aa05de 100644 --- a/tests/test_generator.py +++ b/tests/test_generator.py @@ -34,7 +34,7 @@ def setup_method(self) -> None: def test_reset(self): self.g.add_properties(test_property_list) self.g.reset() - assert self.g.dumps() == f'"{'";"'.join(CSV.header)}"\n' + assert self.g.dumps() == ('"' +'";"'.join(CSV.header) + '"\n') def test_dumps(self): self.g.add_properties(test_property_list) with(open('tests/assets/dummy-result.csv') as file):