Skip to content

Commit 089d971

Browse files
authored
feat: reduce unnessessarry type casting of set/SortedSet (#203)
Signed-off-by: Jan Kowalleck <[email protected]>
1 parent 39637ad commit 089d971

File tree

8 files changed

+49
-49
lines changed

8 files changed

+49
-49
lines changed

cyclonedx/model/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ def __init__(self, *, reference_type: ExternalReferenceType, url: XsUri, comment
457457
self.url = url
458458
self.comment = comment
459459
self.type = reference_type
460-
self.hashes = SortedSet(hashes or [])
460+
self.hashes = hashes or [] # type: ignore
461461

462462
@property
463463
def url(self) -> XsUri:
@@ -1018,8 +1018,8 @@ def __init__(self, *, name: Optional[str] = None, urls: Optional[Iterable[XsUri]
10181018
'One of name, urls or contacts must be supplied for an OrganizationalEntity - none supplied.'
10191019
)
10201020
self.name = name
1021-
self.url = SortedSet(urls or [])
1022-
self.contact = SortedSet(contacts or [])
1021+
self.url = urls or [] # type: ignore
1022+
self.contact = contacts or [] # type: ignore
10231023

10241024
@property
10251025
def name(self) -> Optional[str]:
@@ -1096,8 +1096,8 @@ def __init__(self, *, vendor: Optional[str] = None, name: Optional[str] = None,
10961096
self.vendor = vendor
10971097
self.name = name
10981098
self.version = version
1099-
self.hashes = SortedSet(hashes or [])
1100-
self.external_references = SortedSet(external_references or [])
1099+
self.hashes = hashes or [] # type: ignore
1100+
self.external_references = external_references or [] # type: ignore
11011101

11021102
@property
11031103
def vendor(self) -> Optional[str]:

cyclonedx/model/bom.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ def __init__(self, *, tools: Optional[Iterable[Tool]] = None,
4545
licenses: Optional[Iterable[LicenseChoice]] = None,
4646
properties: Optional[Iterable[Property]] = None) -> None:
4747
self.timestamp = datetime.now(tz=timezone.utc)
48-
self.tools = SortedSet(tools or [])
49-
self.authors = SortedSet(authors or [])
48+
self.tools = tools or [] # type: ignore
49+
self.authors = authors or [] # type: ignore
5050
self.component = component
5151
self.manufacture = manufacture
5252
self.supplier = supplier
53-
self.licenses = SortedSet(licenses or [])
54-
self.properties = SortedSet(properties or [])
53+
self.licenses = licenses or [] # type: ignore
54+
self.properties = properties or [] # type: ignore
5555

5656
if not tools:
5757
self.tools.add(ThisTool)
@@ -239,9 +239,9 @@ def __init__(self, *, components: Optional[Iterable[Component]] = None,
239239
"""
240240
self.uuid = uuid4()
241241
self.metadata = BomMetaData()
242-
self.components = SortedSet(components or [])
243-
self.services = SortedSet(services or [])
244-
self.external_references = SortedSet(external_references or [])
242+
self.components = components or [] # type: ignore
243+
self.services = services or [] # type: ignore
244+
self.external_references = external_references or [] # type: ignore
245245

246246
@property
247247
def uuid(self) -> UUID:

cyclonedx/model/component.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ def __init__(self, *, licenses: Optional[Iterable[LicenseChoice]] = None,
175175
'At least one of `licenses` or `copyright_` must be supplied for a `ComponentEvidence`.'
176176
)
177177

178-
self.licenses = SortedSet(licenses or [])
179-
self.copyright = SortedSet(copyright_ or [])
178+
self.licenses = licenses or [] # type: ignore
179+
self.copyright = copyright_ or [] # type: ignore
180180

181181
@property
182182
def licenses(self) -> "SortedSet[LicenseChoice]":
@@ -334,7 +334,7 @@ def __init__(self, *, type_: PatchClassification, diff: Optional[Diff] = None,
334334
resolves: Optional[Iterable[IssueType]] = None) -> None:
335335
self.type = type_
336336
self.diff = diff
337-
self.resolves = SortedSet(resolves or [])
337+
self.resolves = resolves or [] # type: ignore
338338

339339
@property
340340
def type(self) -> PatchClassification:
@@ -423,11 +423,11 @@ def __init__(self, *, ancestors: Optional[Iterable['Component']] = None,
423423
'provided for `Pedigree`'
424424
)
425425

426-
self.ancestors = SortedSet(ancestors or [])
427-
self.descendants = SortedSet(descendants or [])
428-
self.variants = SortedSet(variants or [])
429-
self.commits = SortedSet(commits or [])
430-
self.patches = SortedSet(patches or [])
426+
self.ancestors = ancestors or [] # type: ignore
427+
self.descendants = descendants or [] # type: ignore
428+
self.variants = variants or [] # type: ignore
429+
self.commits = commits or [] # type: ignore
430+
self.patches = patches or [] # type: ignore
431431
self.notes = notes
432432

433433
@property
@@ -732,16 +732,16 @@ def __init__(self, *, name: str, component_type: ComponentType = ComponentType.L
732732
self.version = version
733733
self.description = description
734734
self.scope = scope
735-
self.hashes = SortedSet(hashes or [])
736-
self.licenses = SortedSet(licenses or [])
735+
self.hashes = hashes or [] # type: ignore
736+
self.licenses = licenses or [] # type: ignore
737737
self.copyright = copyright_
738738
self.cpe = cpe
739739
self.purl = purl
740740
self.swid = swid
741741
self.pedigree = pedigree
742-
self.external_references = SortedSet(external_references or [])
743-
self.properties = SortedSet(properties or [])
744-
self.components = SortedSet(components or [])
742+
self.external_references = external_references or [] # type: ignore
743+
self.properties = properties or [] # type: ignore
744+
self.components = components or [] # type: ignore
745745
self.evidence = evidence
746746
self.release_notes = release_notes
747747

@@ -760,7 +760,7 @@ def __init__(self, *, name: str, component_type: ComponentType = ComponentType.L
760760
'standard', DeprecationWarning
761761
)
762762
if not licenses:
763-
self.licenses = SortedSet([LicenseChoice(license_expression=license_str)])
763+
self.licenses = [LicenseChoice(license_expression=license_str)] # type: ignore
764764

765765
self.__dependencies: "SortedSet[BomRef]" = SortedSet()
766766
self.__vulnerabilites: "SortedSet[Vulnerability]" = SortedSet()

cyclonedx/model/dependency.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Dependency:
3434

3535
def __init__(self, *, ref: BomRef, depends_on: Optional[Iterable[BomRef]] = None) -> None:
3636
self._ref = ref
37-
self.depends_on = SortedSet(depends_on or [])
37+
self.depends_on = depends_on or [] # type: ignore
3838

3939
@property
4040
def ref(self) -> BomRef:

cyclonedx/model/issue.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def __init__(self, *, classification: IssueClassification, id_: Optional[str] =
115115
self.name = name
116116
self.description = description
117117
self.source = source
118-
self.references = SortedSet(references or [])
118+
self.references = references or [] # type: ignore
119119

120120
@property
121121
def type(self) -> IssueClassification:

cyclonedx/model/release_note.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ def __init__(self, *, type_: str, title: Optional[str] = None, featured_image: O
4545
self.social_image = social_image
4646
self.description = description
4747
self.timestamp = timestamp
48-
self.aliases = SortedSet(aliases or [])
49-
self.tags = SortedSet(tags or [])
50-
self.resolves = SortedSet(resolves or [])
51-
self.notes = SortedSet(notes or [])
52-
self.properties = SortedSet(properties or [])
48+
self.aliases = aliases or [] # type: ignore
49+
self.tags = tags or [] # type: ignore
50+
self.resolves = resolves or [] # type: ignore
51+
self.notes = notes or [] # type: ignore
52+
self.properties = properties or [] # type: ignore
5353

5454
@property
5555
def type(self) -> str:

cyclonedx/model/service.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@ def __init__(self, *, name: str, bom_ref: Optional[str] = None, provider: Option
6363
self.name = name
6464
self.version = version
6565
self.description = description
66-
self.endpoints = SortedSet(endpoints or [])
66+
self.endpoints = endpoints or [] # type: ignore
6767
self.authenticated = authenticated
6868
self.x_trust_boundary = x_trust_boundary
69-
self.data = SortedSet(data or [])
70-
self.licenses = SortedSet(licenses or [])
71-
self.external_references = SortedSet(external_references or [])
72-
self.services = SortedSet(services or [])
69+
self.data = data or [] # type: ignore
70+
self.licenses = licenses or [] # type: ignore
71+
self.external_references = external_references or [] # type: ignore
72+
self.services = services or [] # type: ignore
7373
self.release_notes = release_notes
74-
self.properties = SortedSet(properties or [])
74+
self.properties = properties or [] # type: ignore
7575

7676
@property
7777
def bom_ref(self) -> BomRef:

cyclonedx/model/vulnerability.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ class BomTarget:
144144

145145
def __init__(self, *, ref: str, versions: Optional[Iterable[BomTargetVersionRange]] = None) -> None:
146146
self.ref = ref
147-
self.versions = SortedSet(versions or [])
147+
self.versions = versions or [] # type: ignore
148148

149149
@property
150150
def ref(self) -> str:
@@ -207,7 +207,7 @@ def __init__(self, *, state: Optional[ImpactAnalysisState] = None,
207207
)
208208
self.state = state
209209
self.justification = justification
210-
self.response = SortedSet(responses or [])
210+
self.response = responses or [] # type: ignore
211211
self.detail = detail
212212

213213
@property
@@ -719,8 +719,8 @@ def __init__(self, *, organizations: Optional[Iterable[OrganizationalEntity]] =
719719
raise NoPropertiesProvidedException(
720720
'One of `organizations` or `individuals` must be populated - neither were'
721721
)
722-
self.organizations = SortedSet(organizations or [])
723-
self.individuals = SortedSet(individuals or [])
722+
self.organizations = organizations or [] # type: ignore
723+
self.individuals = individuals or [] # type: ignore
724724

725725
@property
726726
def organizations(self) -> "SortedSet[OrganizationalEntity]":
@@ -794,20 +794,20 @@ def __init__(self, *, bom_ref: Optional[str] = None, id: Optional[str] = None,
794794
self._bom_ref = BomRef(value=bom_ref)
795795
self.id = id
796796
self.source = source
797-
self.references = SortedSet(references or [])
798-
self.ratings = SortedSet(ratings or [])
799-
self.cwes = SortedSet(cwes or [])
797+
self.references = references or [] # type: ignore
798+
self.ratings = ratings or [] # type: ignore
799+
self.cwes = cwes or [] # type: ignore
800800
self.description = description
801801
self.detail = detail
802802
self.recommendation = recommendation
803-
self.advisories = SortedSet(advisories or [])
803+
self.advisories = advisories or [] # type: ignore
804804
self.created = created
805805
self.published = published
806806
self.updated = updated
807807
self.credits = credits
808-
self.tools = SortedSet(tools or [])
808+
self.tools = tools or [] # type: ignore
809809
self.analysis = analysis
810-
self.affects = SortedSet(affects_targets or [])
810+
self.affects = affects_targets or [] # type: ignore
811811

812812
if source_name or source_url:
813813
warnings.warn('`source_name` and `source_url` are deprecated - use `source`', DeprecationWarning)

0 commit comments

Comments
 (0)