-
Notifications
You must be signed in to change notification settings - Fork 7
feat: Support for dataclasses as composite types #1242
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
Merged
+151
−25
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
1162236
Support for dataclasses as composite types
rtuck99 42486d5
Update to documentation
rtuck99 7bac9fb
Fix unit test build with example code modules
rtuck99 27be0b5
Make code coverage happy
rtuck99 015ecae
Fix plan schema for composites
rtuck99 cbcac99
Change wording regarding usage of device composites
rtuck99 f701630
Merge remote-tracking branch 'origin/main' into 506_composite_devices…
rtuck99 3288ce3
Merge remote-tracking branch 'origin/main' into 506_composite_devices…
rtuck99 c381eb3
Minor tidyup
rtuck99 3dfa95e
Merge branch 'main' into 506_composite_devices_with_dataclasses
rtuck99 a42f0a9
Merge remote-tracking branch 'origin/main' into 506_composite_devices…
rtuck99 5d7952f
Merge branch 'main' into 506_composite_devices_with_dataclasses
rtuck99 e0e027c
Merge branch 'main' into 506_composite_devices_with_dataclasses
rtuck99 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import pydantic | ||
| from tests.unit_tests.code_examples.device_module import BimorphMirror | ||
|
|
||
|
|
||
| @pydantic.dataclasses.dataclass(config={"arbitrary_types_allowed": True}) | ||
| class MyDeviceComposite: | ||
| oav: BimorphMirror | ||
| # More devices here.... |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| from bluesky.utils import MsgGenerator | ||
| from dodal.common import inject | ||
| from tests.unit_tests.code_examples.device_composite import MyDeviceComposite | ||
|
|
||
|
|
||
| def my_plan( | ||
| parameter_one: int, | ||
| parameter_two: str, | ||
| my_necessary_devices: MyDeviceComposite = inject(""), | ||
| ) -> MsgGenerator[None]: | ||
| # logic goes here | ||
| ... |
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
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.
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.
Do we have any ophyd(-async) devices which are also BaseModels or dataclasses? If not we could remove the
strrequirement and not have to useinject("")for composite devices where it doesn't really make sense.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.
The issue I see with this is that it would also mean that Pydantic models which are not device composites (i.e. parameter models) would also automatically become defaulted, which is probably not what we want.
There is a PR DiamondLightSource/dodal#1649 which at least makes the string argument to inject optional