Skip to content

Commit a3dbf87

Browse files
committed
wip
Signed-off-by: Jan Kowalleck <[email protected]>
1 parent d2f897c commit a3dbf87

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

cyclonedx/_internal/compare.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,29 @@ def __gt__(self, other: Any) -> bool:
8080
return ComparableTuple(self._dict.get(k) for k in keys) \
8181
> ComparableTuple(other._dict.get(k) for k in keys)
8282

83+
def __eq__(self, other):
84+
if not isinstance(other, ComparableDict):
85+
return False
86+
return self._dict == other._dict
87+
88+
def __hash__(self) -> int:
89+
return hash(tuple(self._dict.items()))
90+
91+
def __repr__(self) -> str:
92+
return f'<ComparableDict {self._dict!r}>'
93+
8394

8495
class ComparablePackageURL(ComparableTuple):
8596
"""
8697
Allows comparison of PackageURL, allowing for qualifiers.
8798
"""
8899

89100
def __new__(cls, purl: 'PackageURL') -> 'ComparablePackageURL':
90-
return super().__new__(
91-
ComparablePackageURL, (
92-
purl.type,
93-
purl.namespace,
94-
purl.version,
95-
ComparableDict(purl.qualifiers) if isinstance(purl.qualifiers, dict) else purl.qualifiers,
96-
purl.subpath
97-
))
101+
parts = (
102+
purl.type,
103+
purl.namespace,
104+
purl.version,
105+
ComparableDict(purl.qualifiers) if isinstance(purl.qualifiers, dict) else purl.qualifiers,
106+
purl.subpath
107+
)
108+
return super(ComparablePackageURL, cls).__new__(cls, parts)

0 commit comments

Comments
 (0)