spdx_tools.spdx.model.annotation

 1# SPDX-FileCopyrightText: 2022 spdx contributors
 2#
 3# SPDX-License-Identifier: Apache-2.0
 4from datetime import datetime
 5from enum import Enum, auto
 6
 7from spdx_tools.common.typing.dataclass_with_properties import dataclass_with_properties
 8from spdx_tools.common.typing.type_checks import check_types_and_set_values
 9from spdx_tools.spdx.model import Actor
10
11
12class AnnotationType(Enum):
13    REVIEW = auto()
14    OTHER = auto()
15
16
17@dataclass_with_properties
18class Annotation:
19    spdx_id: str
20    annotation_type: AnnotationType
21    annotator: Actor
22    annotation_date: datetime
23    annotation_comment: str
24
25    def __init__(
26        self,
27        spdx_id: str,
28        annotation_type: AnnotationType,
29        annotator: Actor,
30        annotation_date: datetime,
31        annotation_comment: str,
32    ):
33        check_types_and_set_values(self, locals())
class AnnotationType(enum.Enum):
13class AnnotationType(Enum):
14    REVIEW = auto()
15    OTHER = auto()

Create a collection of name/value pairs.

Example enumeration:

>>> class Color(Enum):
...     RED = 1
...     BLUE = 2
...     GREEN = 3

Access them by:

  • attribute access::
>>> Color.RED
<Color.RED: 1>
  • value lookup:
>>> Color(1)
<Color.RED: 1>
  • name lookup:
>>> Color['RED']
<Color.RED: 1>

Enumerations can be iterated over, and know how many members they have:

>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

Methods can be added to enumerations, and members can have their own attributes -- see the documentation for details.

REVIEW = <AnnotationType.REVIEW: 1>
OTHER = <AnnotationType.OTHER: 2>
Inherited Members
enum.Enum
name
value
@dataclass_with_properties
class Annotation:
18@dataclass_with_properties
19class Annotation:
20    spdx_id: str
21    annotation_type: AnnotationType
22    annotator: Actor
23    annotation_date: datetime
24    annotation_comment: str
25
26    def __init__(
27        self,
28        spdx_id: str,
29        annotation_type: AnnotationType,
30        annotator: Actor,
31        annotation_date: datetime,
32        annotation_comment: str,
33    ):
34        check_types_and_set_values(self, locals())
Annotation( spdx_id: str, annotation_type: AnnotationType, annotator: spdx_tools.spdx.model.actor.Actor, annotation_date: datetime.datetime, annotation_comment: str)
26    def __init__(
27        self,
28        spdx_id: str,
29        annotation_type: AnnotationType,
30        annotator: Actor,
31        annotation_date: datetime,
32        annotation_comment: str,
33    ):
34        check_types_and_set_values(self, locals())
spdx_id: str
47    def get_field(self) -> field_type:
48        return getattr(self, f"_{field_name}")
annotation_type: AnnotationType
47    def get_field(self) -> field_type:
48        return getattr(self, f"_{field_name}")
annotator: spdx_tools.spdx.model.actor.Actor
47    def get_field(self) -> field_type:
48        return getattr(self, f"_{field_name}")
annotation_date: datetime.datetime
47    def get_field(self) -> field_type:
48        return getattr(self, f"_{field_name}")
annotation_comment: str
47    def get_field(self) -> field_type:
48        return getattr(self, f"_{field_name}")