Add static and runtime type checking to the CAPI2 Schema.#781
Open
HU90m wants to merge 3 commits into
Open
Conversation
Python 3.10 has a nice syntax features for type annotations, such as `|` unions, and 3.9 will be end of life by the end of 2025. Pydantic has been added to allow runtime type checking.
ArkoshEternal
approved these changes
May 18, 2026
Collaborator
ArkoshEternal
left a comment
There was a problem hiding this comment.
Since this is majorly non-breaking, and checking would require that we have active fusesoc runs to check against edge-cases that are not in the existing test framework, it may make sense to add the local checks into the CI for fusesoc.
I think we should merge this in as an initial set and then we may have to make revisions after we do more integration into the rest of the codebase
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I've made these changes such that the interface of
fusesoc.core.Coreremains unchanged. This was done in the interest of keeping changes minimal.We can change this interface, and make use of the CAPI2 objects, as we expand type checking into the rest of the repository in later PRs.
As discussed, I've dumped the python version. Python 3.9 is end-of-life and 3.10 offers many ergonomic features. See: #734
Pydantic has been used for runtime type checking, which saves a lot of schema validation logic. Pydantic can be used to generate the jsonschema. A future PR could use
sphinx-autodoc-pydanticto generate nice documentation, remove use of the old jsonschema and provide the jsonschema generated from Pydantic for people creating tools in other languages. This may be of interest to you @amykyta3Both mypy and ty have been added to pre-commit for static type checking.
Beyond the normal test suite, I also checked for changes in the output of:
NB: e7c243b broke some opentitan core files, so has to be reverted whenever testing against opentitan. Something to be aware of when updating FuseSoC in opentitan @machshev