1
1
# SPDX-FileCopyrightText: 2022 spdx contributors
2
2
#
3
3
# SPDX-License-Identifier: Apache-2.0
4
- from beartype .typing import Dict , List , Optional
4
+ from beartype .typing import Dict , List , Optional , Set
5
5
6
6
from spdx_tools .common .typing .constructor_type_errors import ConstructorTypeErrors
7
7
from spdx_tools .spdx .model import Relationship , RelationshipType
@@ -35,9 +35,9 @@ def parse_all_relationships(self, input_doc_dict: Dict) -> List[Relationship]:
35
35
document_describes : List [str ] = delete_duplicates_from_list (input_doc_dict .get ("documentDescribes" , []))
36
36
doc_spdx_id : Optional [str ] = input_doc_dict .get ("SPDXID" )
37
37
38
- existing_relationships_without_comments : List [Relationship ] = self .get_all_relationships_without_comments (
38
+ existing_relationships_without_comments : Set [Relationship ] = set ( self .get_all_relationships_without_comments (
39
39
relationships
40
- )
40
+ ))
41
41
relationships .extend (
42
42
parse_field_or_log_error (
43
43
self .logger ,
@@ -52,9 +52,6 @@ def parse_all_relationships(self, input_doc_dict: Dict) -> List[Relationship]:
52
52
)
53
53
54
54
package_dicts : List [Dict ] = input_doc_dict .get ("packages" , [])
55
- existing_relationships_without_comments : List [Relationship ] = self .get_all_relationships_without_comments (
56
- relationships
57
- )
58
55
59
56
relationships .extend (
60
57
parse_field_or_log_error (
@@ -110,7 +107,7 @@ def parse_relationship_type(relationship_type_str: str) -> RelationshipType:
110
107
return relationship_type
111
108
112
109
def parse_document_describes (
113
- self , doc_spdx_id : str , described_spdx_ids : List [str ], existing_relationships : List [Relationship ]
110
+ self , doc_spdx_id : str , described_spdx_ids : List [str ], existing_relationships : Set [Relationship ]
114
111
) -> List [Relationship ]:
115
112
logger = Logger ()
116
113
describes_relationships = []
@@ -131,10 +128,11 @@ def parse_document_describes(
131
128
return describes_relationships
132
129
133
130
def parse_has_files (
134
- self , package_dicts : List [Dict ], existing_relationships : List [Relationship ]
131
+ self , package_dicts : List [Dict ], existing_relationships : Set [Relationship ]
135
132
) -> List [Relationship ]:
136
133
# assume existing relationships are stripped of comments
137
134
logger = Logger ()
135
+
138
136
contains_relationships = []
139
137
for package in package_dicts :
140
138
package_spdx_id : Optional [str ] = package .get ("SPDXID" )
@@ -160,7 +158,7 @@ def parse_has_files(
160
158
return contains_relationships
161
159
162
160
def check_if_relationship_exists (
163
- self , relationship : Relationship , existing_relationships : List [Relationship ]
161
+ self , relationship : Relationship , existing_relationships : Set [Relationship ]
164
162
) -> bool :
165
163
# assume existing relationships are stripped of comments
166
164
if relationship in existing_relationships :
0 commit comments