Improve doctrsings and error messages
@@ -58,9 +58,6 @@ class VulnerabilitySeverity:
value: str
def to_dict(self):
- """
- Return a serializable dict that can be converted back using self.from_dict
- """
return {
"system": self.system.identifier,
"value": self.value,
@@ -69,7 +66,8 @@ class VulnerabilitySeverity:
@classmethod
def from_dict(cls, severity: dict):
"""
- Return a VulnerabilitySeverity object from dict generated by self.to_dict
+ Return a VulnerabilitySeverity object from a ``severity`` mapping of
+ VulnerabilitySeverity data.
"""
return cls(system=SCORING_SYSTEMS[severity["system"]], value=severity["value"])
@@ -90,9 +88,6 @@ class Reference:
return Reference(reference_id=self.reference_id, url=self.url, severities=severities)
def to_dict(self):
- """
- Return a serializable dict that can be converted back using self.from_dict
- """
return {
"reference_id": self.reference_id,
"url": self.url,
@@ -101,9 +96,6 @@ class Reference:
@classmethod
def from_dict(cls, ref: dict):
- """
- Return a Reference object from dict generated by self.to_dict
- """
return cls(
reference_id=ref["reference_id"],
url=ref["url"],
@@ -128,9 +120,9 @@ class NoAffectedPackages(Exception):
@dataclasses.dataclass(order=True, frozen=True)
class AffectedPackage:
"""
- Contains a range of affected versions and a fixed version of a given package
- The PackageURL supplied must *not* have a version
- It must contain either `affected_version_range` or `fixed_version`
+ Relate a Package URL with a range of affected versions and a fixed version.
+ The Package URL must *not* have a version.
+ AffectedPackage must contain either ``affected_version_range`` or ``fixed_version``.
"""
package: PackageURL
@@ -139,18 +131,20 @@ class AffectedPackage:
def __post_init__(self):
if self.package.version:
- raise ValueError("The PackageURL supplied must not have a version")
+ raise ValueError(f"Affected Package URL {self.package!r} cannot have a version.")
+
if not (self.affected_version_range or self.fixed_version):
raise ValueError(
- "Affected Package should at least have either a fixed version or affected version range"
+ f"Affected Package {self.package!r} should have either a fixed version or an "
+ "affected version range."
)
def get_fixed_purl(self):
"""
- Return PackageURL corresponding to object's fixed_version
+ Return a Package URL corresponding to object's fixed_version
"""
if not self.fixed_version:
- raise ValueError("Affected package should have a fixed version")
+ raise ValueError(f"Affected Package {self.package!r} does not have a fixed version")
fixed_purl = self.package._replace(version=str(self.fixed_version))
return fixed_purl
