Skip to content

Commit

Permalink
typing: fix dataclass_with_properties for static type checkers
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kukovecz committed Sep 16, 2024
1 parent 1973ce1 commit fc96cf2
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/spdx_tools/common/typing/dataclass_with_properties.py
Original file line number Diff line number Diff line change
@@ -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."""
Expand Down

0 comments on commit fc96cf2

Please sign in to comment.