Skip to content
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

setting attributes of a packageurl object #87

Open
armijnhemel opened this issue May 11, 2022 · 1 comment
Open

setting attributes of a packageurl object #87

armijnhemel opened this issue May 11, 2022 · 1 comment

Comments

@armijnhemel
Copy link

Is it possible to set attributes (such as version) in a packageurl object?

>>> import packageurl
>>> purl = packageurl.PackageURL.from_string('pkg:generic/busybox')
>>> purl.version
>>> purl.version = 3
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: can't set attribute
@tdruez
Copy link
Collaborator

tdruez commented Jun 27, 2022

See also #82

@armijnhemel The PackageURL class is actually generated from a namedtuple and since namedtuple objects are immutable, you cannot modified their values once initialized.

As a workaround, you can re-use the function evolve_purl available at aboutcode-org/vulnerablecode@039babf#diff-938a299f8406c1d3defaec48838bc4f6f1307635f5d2ba36e9777227cedbb383R144

Once implemented, your code would look something like:

>>> from packageurl import PackageURL
>>> purl = PackageURL.from_string('pkg:generic/busybox')
>>> evolve_purl(purl, version="3")
PackageURL(type='generic', namespace=None, name='busybox', version='3', qualifiers={}, subpath=None)

@pombredanne what's your though on refactoring PackageURL from a namedtuple to a proper class?
In any case, in the short term, it would make sense to implement evolve_purl on the PackageURL class as suggested in #82.
What about a simple update() method, instead of the evolve_purl() name?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants