Skip to content

feat!: de/serialize with cattrs#934

Draft
jkugler wants to merge 7 commits intoCycloneDX:mainfrom
jkugler:jkugler/convert_to_cattrs
Draft

feat!: de/serialize with cattrs#934
jkugler wants to merge 7 commits intoCycloneDX:mainfrom
jkugler:jkugler/convert_to_cattrs

Conversation

@jkugler
Copy link
Contributor

@jkugler jkugler commented Feb 5, 2026

Description

Moves away from py-serialiable to attrs and cattrs. The primary motivation for this is better type inference and moving away from py-serializable (which I'm been told was an eventual goal; correct me if wrong).
Resolves or fixes issue: None

AI Tool Disclosure

  • My contribution does not include any AI-generated content
  • My contribution includes AI-generated content, as disclosed below:
    • AI Tools: CursorIDE
    • LLMs and versions: claude-4.5-opus-high
    • Prompts: I don't remember what my original prompt was, as my scroll-back has lost it, but it was along the lines of "Convert the project to use attrs and cattrs instead of py-serializable.

Affirmation

This is a large and very invasive and breaking changing. I fully understand if the project would rather not accept it. I'm happy to discuss how it might be improved if there is interest, but a desire to make the PR better.

@jkugler jkugler requested a review from a team as a code owner February 5, 2026 22:03
@jkugler
Copy link
Contributor Author

jkugler commented Feb 5, 2026

Sorry, I didn't catch the title, and it won't let me change it. :)

@read-the-docs-community
Copy link

read-the-docs-community bot commented Feb 5, 2026

jkugler and others added 6 commits February 5, 2026 13:04
All tests pass

Signed-off-by: Joshua Kugler <tek30584@adobe.com>
…neDX#929)

Updates the requirements on [mypy](https://github.com/python/mypy) to
permit the latest version.
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/python/mypy/blob/master/CHANGELOG.md">mypy's
changelog</a>.</em></p>
<blockquote>
<h3>Mypy 1.19.1</h3>
<ul>
<li>Fix noncommutative joins with bounded TypeVars (Shantanu, PR <a
href="https://redirect.github.com/python/mypy/pull/20345">20345</a>)</li>
<li>Respect output format for cached runs by serializing raw errors in
cache metas (Ivan Levkivskyi, PR <a
href="https://redirect.github.com/python/mypy/pull/20372">20372</a>)</li>
<li>Allow <code>types.NoneType</code> in match cases (A5rocks, PR <a
href="https://redirect.github.com/python/mypy/pull/20383">20383</a>)</li>
<li>Fix mypyc generator regression with empty tuple (BobTheBuidler, PR
<a
href="https://redirect.github.com/python/mypy/pull/20371">20371</a>)</li>
<li>Fix crash involving Unpack-ed TypeVarTuple (Shantanu, PR <a
href="https://redirect.github.com/python/mypy/pull/20323">20323</a>)</li>
<li>Fix crash on star import of redefinition (Ivan Levkivskyi, PR <a
href="https://redirect.github.com/python/mypy/pull/20333">20333</a>)</li>
<li>Fix crash on typevar with forward ref used in other module (Ivan
Levkivskyi, PR <a
href="https://redirect.github.com/python/mypy/pull/20334">20334</a>)</li>
<li>Fail with an explicit error on PyPy (Ivan Levkivskyi, PR <a
href="https://redirect.github.com/python/mypy/pull/20389">20389</a>)</li>
</ul>
<h3>Acknowledgements</h3>
<p>Thanks to all mypy contributors who contributed to this release:</p>
<ul>
<li>A5rocks</li>
<li>BobTheBuidler</li>
<li>bzoracler</li>
<li>Chainfire</li>
<li>Christoph Tyralla</li>
<li>David Foster</li>
<li>Frank Dana</li>
<li>Guo Ci</li>
<li>iap</li>
<li>Ivan Levkivskyi</li>
<li>James Hilton-Balfe</li>
<li>jhance</li>
<li>Joren Hammudoglu</li>
<li>Jukka Lehtosalo</li>
<li>KarelKenens</li>
<li>Kevin Kannammalil</li>
<li>Marc Mueller</li>
<li>Michael Carlstrom</li>
<li>Michael J. Sullivan</li>
<li>Piotr Sawicki</li>
<li>Randolf Scholz</li>
<li>Shantanu</li>
<li>Sigve Sebastian Farstad</li>
<li>sobolevn</li>
<li>Stanislav Terliakov</li>
<li>Stephen Morton</li>
<li>Theodore Ando</li>
<li>Thiago J. Barbalho</li>
<li>wyattscarpenter</li>
</ul>
<p>I’d also like to thank my employer, Dropbox, for supporting mypy
development.</p>
<h2>Mypy 1.18</h2>
<p>We’ve just uploaded mypy 1.18.1 to the Python Package Index (<a
href="https://pypi.org/project/mypy/">PyPI</a>).
Mypy is a static type checker for Python. This release includes new
features, performance</p>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/python/mypy/commit/412c19a6bde31e7afa7f41afdf8356664689ae80"><code>412c19a</code></a>
Bump version to 1.19.1</li>
<li><a
href="https://github.com/python/mypy/commit/20aea0a6ca0710f5427239bdd2fd8e8bf1caf634"><code>20aea0a</code></a>
Update changelog for 1.19.1 (<a
href="https://redirect.github.com/python/mypy/issues/20414">#20414</a>)</li>
<li><a
href="https://github.com/python/mypy/commit/2b23b507524bf1bd7513eea6f2a16fb91e072cb6"><code>2b23b50</code></a>
Serialize raw errors in cache metas (<a
href="https://redirect.github.com/python/mypy/issues/20372">#20372</a>)</li>
<li><a
href="https://github.com/python/mypy/commit/f60f90fb8872bf722e32aefd548daaf6d8560e05"><code>f60f90f</code></a>
Fail on PyPy in main instead of setup.py (<a
href="https://redirect.github.com/python/mypy/issues/20389">#20389</a>)</li>
<li><a
href="https://github.com/python/mypy/commit/58d485b4ea4776e0b9d4045b306cb0818ecc2aa6"><code>58d485b</code></a>
Fail with an explicit error on PyPy (<a
href="https://redirect.github.com/python/mypy/issues/20384">#20384</a>)</li>
<li><a
href="https://github.com/python/mypy/commit/a4b31a26788b70c4a2a19adbafa2bbda43dc2e8b"><code>a4b31a2</code></a>
Allow <code>types.NoneType</code> in match cases (<a
href="https://redirect.github.com/python/mypy/issues/20383">#20383</a>)</li>
<li><a
href="https://github.com/python/mypy/commit/8a6eff478416cd3ed3931a6ed77ce61c88ab69e9"><code>8a6eff4</code></a>
[mypyc] fix generator regression with empty tuple (<a
href="https://redirect.github.com/python/mypy/issues/20371">#20371</a>)</li>
<li><a
href="https://github.com/python/mypy/commit/70eceea682c041c0d8e8462dffef9c7bb252e014"><code>70eceea</code></a>
Fix noncommutative joins with bounded TypeVars (<a
href="https://redirect.github.com/python/mypy/issues/20345">#20345</a>)</li>
<li><a
href="https://github.com/python/mypy/commit/3890fc49bf7cc02db04b1e63eb2540aaacdeecc0"><code>3890fc4</code></a>
Fix crash involving Unpack-ed TypeVarTuple (<a
href="https://redirect.github.com/python/mypy/issues/20323">#20323</a>)</li>
<li><a
href="https://github.com/python/mypy/commit/c93d917a86993e06dcc88e508f28f4f5199ce1c8"><code>c93d917</code></a>
Fix crash on star import of redefinition (<a
href="https://redirect.github.com/python/mypy/issues/20333">#20333</a>)</li>
<li>Additional commits viewable in <a
href="https://github.com/python/mypy/compare/v1.19.0...v1.19.1">compare
view</a></li>
</ul>
</details>
<br />

<details>
<summary>Most Recent Ignore Conditions Applied to This Pull
Request</summary>

| Dependency Name | Ignore Conditions |
| --- | --- |
| mypy | [>= 0.971.a, < 0.972] |
</details>

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)

</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: Joshua Kugler <tek30584@adobe.com>
might fix
https://github.com/CycloneDX/cyclonedx-python-lib/actions/runs/20417619990/job/58663570418#step:6:193

---------

Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
Signed-off-by: Joshua Kugler <tek30584@adobe.com>
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
Signed-off-by: Joshua Kugler <tek30584@adobe.com>
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
Signed-off-by: Joshua Kugler <tek30584@adobe.com>
Signed-off-by: Joshua Kugler <tek30584@adobe.com>
@jkugler jkugler force-pushed the jkugler/convert_to_cattrs branch from 77f4a74 to d202375 Compare February 5, 2026 22:05
https://cyclonedx.org/docs/1.7/json/#tab-pane_vulnerabilities_items_affects_items_versions_items_oneOf_i0
"""

def __init__(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removing this __init__ is a undesired beaking change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An __init__ is added implicitly by the cattrs @define decorator. Things like BomTargetVersionRange(range='2.0.0 - 2.1.0', status=ImpactAnalysisAffectedStatus.AFFECTED) from https://github.com/CycloneDX/cyclonedx-python-lib/blob/main/tests/test_model_vulnerability.py#L396 still work.

The only changes made to the tests directory were changes in snapshots. No code in tests was changed.

The if not version and not range line removed in line 81 was moved to the __attrs_post_init__ function on line 105.

Hope that clears some things up!

@jkowalleck
Copy link
Member

i see much to much breaking changes - not going to fully review nor merge this.

will put this as a "draft"

@jkowalleck jkowalleck marked this pull request as draft February 6, 2026 13:20
@jkowalleck jkowalleck changed the title Jkugler/convert to cattrs feat!: de/serialize with cattrs Feb 6, 2026
@jkugler
Copy link
Contributor Author

jkugler commented Feb 6, 2026

will put this as a "draft"

Sure thing, no worries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants