spdx_tools.spdx3.model.annotation

 1# SPDX-FileCopyrightText: 2023 spdx contributors
 2#
 3# SPDX-License-Identifier: Apache-2.0
 4from dataclasses import field
 5from enum import Enum, auto
 6
 7from beartype.typing import List, Optional
 8
 9from spdx_tools.common.typing.dataclass_with_properties import dataclass_with_properties
10from spdx_tools.common.typing.type_checks import check_types_and_set_values
11from spdx_tools.spdx3.model import CreationInfo, Element, ExternalIdentifier, ExternalReference, IntegrityMethod
12
13
14class AnnotationType(Enum):
15    REVIEW = auto()
16    OTHER = auto()
17
18
19@dataclass_with_properties
20class Annotation(Element):
21    annotation_type: AnnotationType = None
22    subject: str = None
23    content_type: List[str] = field(default_factory=list)  # placeholder for MediaType
24    statement: Optional[str] = None
25
26    def __init__(
27        self,
28        spdx_id: str,
29        annotation_type: AnnotationType,
30        subject: str,
31        creation_info: Optional[CreationInfo] = None,
32        name: Optional[str] = None,
33        summary: Optional[str] = None,
34        description: Optional[str] = None,
35        comment: Optional[str] = None,
36        verified_using: List[IntegrityMethod] = None,
37        external_reference: List[ExternalReference] = None,
38        external_identifier: List[ExternalIdentifier] = None,
39        extension: Optional[str] = None,
40        content_type: List[str] = None,
41        statement: Optional[str] = None,
42    ):
43        verified_using = [] if verified_using is None else verified_using
44        external_reference = [] if external_reference is None else external_reference
45        external_identifier = [] if external_identifier is None else external_identifier
46        content_type = [] if content_type is None else content_type
47        check_types_and_set_values(self, locals())
class AnnotationType(enum.Enum):
15class AnnotationType(Enum):
16    REVIEW = auto()
17    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(spdx_tools.spdx3.model.element.Element):
20@dataclass_with_properties
21class Annotation(Element):
22    annotation_type: AnnotationType = None
23    subject: str = None
24    content_type: List[str] = field(default_factory=list)  # placeholder for MediaType
25    statement: Optional[str] = None
26
27    def __init__(
28        self,
29        spdx_id: str,
30        annotation_type: AnnotationType,
31        subject: str,
32        creation_info: Optional[CreationInfo] = None,
33        name: Optional[str] = None,
34        summary: Optional[str] = None,
35        description: Optional[str] = None,
36        comment: Optional[str] = None,
37        verified_using: List[IntegrityMethod] = None,
38        external_reference: List[ExternalReference] = None,
39        external_identifier: List[ExternalIdentifier] = None,
40        extension: Optional[str] = None,
41        content_type: List[str] = None,
42        statement: Optional[str] = None,
43    ):
44        verified_using = [] if verified_using is None else verified_using
45        external_reference = [] if external_reference is None else external_reference
46        external_identifier = [] if external_identifier is None else external_identifier
47        content_type = [] if content_type is None else content_type
48        check_types_and_set_values(self, locals())
Annotation( spdx_id: str, annotation_type: AnnotationType, subject: str, creation_info: Optional[spdx_tools.spdx3.model.creation_info.CreationInfo] = None, name: Optional[str] = None, summary: Optional[str] = None, description: Optional[str] = None, comment: Optional[str] = None, verified_using: list[spdx_tools.spdx3.model.integrity_method.IntegrityMethod] = None, external_reference: list[spdx_tools.spdx3.model.external_reference.ExternalReference] = None, external_identifier: list[spdx_tools.spdx3.model.external_identifier.ExternalIdentifier] = None, extension: Optional[str] = None, content_type: list[str] = None, statement: Optional[str] = None)
27    def __init__(
28        self,
29        spdx_id: str,
30        annotation_type: AnnotationType,
31        subject: str,
32        creation_info: Optional[CreationInfo] = None,
33        name: Optional[str] = None,
34        summary: Optional[str] = None,
35        description: Optional[str] = None,
36        comment: Optional[str] = None,
37        verified_using: List[IntegrityMethod] = None,
38        external_reference: List[ExternalReference] = None,
39        external_identifier: List[ExternalIdentifier] = None,
40        extension: Optional[str] = None,
41        content_type: List[str] = None,
42        statement: Optional[str] = None,
43    ):
44        verified_using = [] if verified_using is None else verified_using
45        external_reference = [] if external_reference is None else external_reference
46        external_identifier = [] if external_identifier is None else external_identifier
47        content_type = [] if content_type is None else content_type
48        check_types_and_set_values(self, locals())
annotation_type: AnnotationType
47    def get_field(self) -> field_type:
48        return getattr(self, f"_{field_name}")
subject: str
47    def get_field(self) -> field_type:
48        return getattr(self, f"_{field_name}")
content_type: list[str]
47    def get_field(self) -> field_type:
48        return getattr(self, f"_{field_name}")
statement: Optional[str]
47    def get_field(self) -> field_type:
48        return getattr(self, f"_{field_name}")