From f34424b35565cc55335ce5ed8998072b40b78b09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1nos=20Kukovecz?= Date: Mon, 16 Sep 2024 10:15:22 +0200 Subject: [PATCH] typing: fix dataclass_with_properties for static type checkers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Using dataclass_transform decorators, we can tell the static type checkers that the class under construction is indeed a dataclass. More info: https://typing.readthedocs.io/en/latest/spec/dataclasses.html Signed-off-by: János Kukovecz --- src/spdx_tools/common/typing/dataclass_with_properties.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/spdx_tools/common/typing/dataclass_with_properties.py b/src/spdx_tools/common/typing/dataclass_with_properties.py index 3f13950d5..dbcb76ee3 100644 --- a/src/spdx_tools/common/typing/dataclass_with_properties.py +++ b/src/spdx_tools/common/typing/dataclass_with_properties.py @@ -1,12 +1,14 @@ # SPDX-FileCopyrightText: 2022 spdx contributors # # SPDX-License-Identifier: Apache-2.0 -from dataclasses import dataclass +from dataclasses import dataclass, field +from typing import dataclass_transform from beartype import beartype from beartype.roar import BeartypeCallHintException +@dataclass_transform(field_specifiers=(field,)) def dataclass_with_properties(cls): """Decorator to generate a dataclass with properties out of the class' value:type list. Their getters and setters will be subjected to the @typechecked decorator to ensure type conformity."""