Skip to content

Commit fc96cf2

Browse files
committed
typing: fix dataclass_with_properties for static type checkers
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
1 parent 1973ce1 commit fc96cf2

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/spdx_tools/common/typing/dataclass_with_properties.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# SPDX-FileCopyrightText: 2022 spdx contributors
22
#
33
# SPDX-License-Identifier: Apache-2.0
4-
from dataclasses import dataclass
4+
from dataclasses import dataclass, field
5+
from typing import dataclass_transform
56

67
from beartype import beartype
78
from beartype.roar import BeartypeCallHintException
89

910

11+
@dataclass_transform(field_specifiers=(field,))
1012
def dataclass_with_properties(cls):
1113
"""Decorator to generate a dataclass with properties out of the class' value:type list.
1214
Their getters and setters will be subjected to the @typechecked decorator to ensure type conformity."""

0 commit comments

Comments
 (0)