11# SPDX-FileCopyrightText: 2022 spdx contributors
22#
33# SPDX-License-Identifier: Apache-2.0
4- from beartype .typing import Dict , List , Optional
4+ from beartype .typing import Dict , List , Optional , Set
55
66from spdx_tools .common .typing .constructor_type_errors import ConstructorTypeErrors
77from spdx_tools .spdx .model import Relationship , RelationshipType
@@ -35,9 +35,9 @@ def parse_all_relationships(self, input_doc_dict: Dict) -> List[Relationship]:
3535 document_describes : List [str ] = delete_duplicates_from_list (input_doc_dict .get ("documentDescribes" , []))
3636 doc_spdx_id : Optional [str ] = input_doc_dict .get ("SPDXID" )
3737
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 (
3939 relationships
40- )
40+ ))
4141 relationships .extend (
4242 parse_field_or_log_error (
4343 self .logger ,
@@ -52,9 +52,6 @@ def parse_all_relationships(self, input_doc_dict: Dict) -> List[Relationship]:
5252 )
5353
5454 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- )
5855
5956 relationships .extend (
6057 parse_field_or_log_error (
@@ -110,7 +107,7 @@ def parse_relationship_type(relationship_type_str: str) -> RelationshipType:
110107 return relationship_type
111108
112109 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 ]
114111 ) -> List [Relationship ]:
115112 logger = Logger ()
116113 describes_relationships = []
@@ -131,10 +128,11 @@ def parse_document_describes(
131128 return describes_relationships
132129
133130 def parse_has_files (
134- self , package_dicts : List [Dict ], existing_relationships : List [Relationship ]
131+ self , package_dicts : List [Dict ], existing_relationships : Set [Relationship ]
135132 ) -> List [Relationship ]:
136133 # assume existing relationships are stripped of comments
137134 logger = Logger ()
135+
138136 contains_relationships = []
139137 for package in package_dicts :
140138 package_spdx_id : Optional [str ] = package .get ("SPDXID" )
@@ -160,7 +158,7 @@ def parse_has_files(
160158 return contains_relationships
161159
162160 def check_if_relationship_exists (
163- self , relationship : Relationship , existing_relationships : List [Relationship ]
161+ self , relationship : Relationship , existing_relationships : Set [Relationship ]
164162 ) -> bool :
165163 # assume existing relationships are stripped of comments
166164 if relationship in existing_relationships :
0 commit comments