-
-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
serialization filter: any one expressen preferred #371
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -18,12 +18,15 @@ | |||||||||
Set of helper classes for use with ``serializable`` when conducting (de-)serialization. | ||||||||||
""" | ||||||||||
|
||||||||||
import warnings | ||||||||||
from typing import List | ||||||||||
from uuid import UUID | ||||||||||
|
||||||||||
# See https://github.com/package-url/packageurl-python/issues/65 | ||||||||||
from packageurl import PackageURL | ||||||||||
from serializable.helpers import BaseHelper | ||||||||||
|
||||||||||
from ..model import LicenseChoice | ||||||||||
from ..model.bom_ref import BomRef | ||||||||||
|
||||||||||
|
||||||||||
|
@@ -76,3 +79,23 @@ def deserialize(cls, o: object) -> UUID: | |||||||||
return UUID(str(o)) | ||||||||||
except ValueError: | ||||||||||
raise ValueError(f'UUID string supplied ({o}) does not parse!') | ||||||||||
|
||||||||||
|
||||||||||
class LicensesHelper(BaseHelper): | ||||||||||
|
||||||||||
@classmethod | ||||||||||
def serialize(cls, o: object) -> List[LicenseChoice]: | ||||||||||
# need to call `list(o)`, because `o` could be any iterable. | ||||||||||
licenses: List[LicenseChoice] = list(o) # type: ignore[call-overload] | ||||||||||
if len(licenses) > 1: | ||||||||||
expression = next((license for license in licenses if license.expression), None) | ||||||||||
if expression: | ||||||||||
warnings.warn(f'Licenses: found an expression {expression!r}, dropping the rest of: {licenses!r}', | ||||||||||
RuntimeWarning) | ||||||||||
return [expression] | ||||||||||
return licenses | ||||||||||
|
||||||||||
@classmethod | ||||||||||
def deserialize(cls, o: object) -> List[LicenseChoice]: | ||||||||||
raise NotImplementedError | ||||||||||
return [LicenseChoice.from_json(data) for data in o] | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. vulture-100: unreachable code after 'raise' ℹ️ Expand to see all @sonatype-lift commandsYou can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.
Note: When talking to LiftBot, you need to refresh the page to see its response. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
E1101: Class 'LicenseChoice' has no 'from_json' member
ℹ️ Expand to see all @sonatype-lift commands
You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.
@sonatype-lift ignore
@sonatype-lift ignoreall
@sonatype-lift exclude <file|issue|path|tool>
file|issue|path|tool
from Lift findings by updating your config.toml fileNote: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.