-
Notifications
You must be signed in to change notification settings - Fork 182
feat: Generate context types from schema #2133
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
Open
effigies
wants to merge
10
commits into
bids-standard:maint/1.10.0
Choose a base branch
from
effigies:feat/context-types
base: maint/1.10.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
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
9c99674
to
bf537b3
Compare
bf537b3
to
dcaba25
Compare
3432cb1
to
f0a243f
Compare
@ubdbra001 Just a heads up on this. This is going to replace much of bids-standard/python-validator#24, which will instead do something like what I have above. |
56fdb92
to
c4f00a7
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
exclude-from-changelog
This item will not feature in the automatically generated changelog
schema-code
Updates or changes to the code used to parse, filter, and render the schema.
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.
This PR follows-up #2115 by procedurally generating Python types from the
schema.meta.context
object. This uses structural subtyping to allow for a variety of implementations to satisfy type-checkers, while also providing default standard library dataclass implementations.The dataclass fields are annotated with protocols instead of one another, so that you can flexibly mix-and-match the provided dataclasses and your own classes, for example:
Dataset
is assignable to a variable annotated asbidsschematools.types.protocols.Dataset
, but notbidsschematools.types.context.Dataset
.Protocols doc: https://bidsschematools--2133.org.readthedocs.build/en/2133/api/bidsschematools.types.protocols.html
Dataclasses doc: https://bidsschematools--2133.org.readthedocs.build/en/2133/api/bidsschematools.types.context.html
As with #2115, the goal here is to remain dynamic in editable installation mode, constructing and
exec
ing the module on-the-fly, while freezing a copy for optimal loading when performing full installations or building packages.