Repository navigation
Deserialise plan method arguments by replacing types instead of building custom validators - #154
Conversation
|
Makes sense and much more concise, good job! We also need to make sure we don't lose the functionality introduced by #131 |
|
RE the three failing tests, why is it invalid to have untyped arguments? I can imagine it's not really that useful but I can't see why it'd be a problem. |
Should now handle concrete types as well as protocols. |
The idea is that the arguments are essentially turned into an API schema. So it's not a problem to have untyped arguments if we have a default type of "any valid JSON". I'm on the fence about allowing that, any strong opinions @keithralphs @DiamondJoseph? |
Codecov Report
@@ Coverage Diff @@
## main #154 +/- ##
==========================================
+ Coverage 74.47% 83.00% +8.53%
==========================================
Files 37 39 +2
Lines 1050 1024 -26
==========================================
+ Hits 782 850 +68
+ Misses 268 174 -94
... and 10 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
|
I think enforcing typing makes our life easier long term, as plans are eventually going under code review then sitting in repositories for years while support staff change until they're updated and makes potential auto-generation for GUIs etc. possible down the line. It seems a very small requirement that is easily enforced and has potential benefit. |
|
Checks to enforce at least an |
callumforrester
left a comment
There was a problem hiding this comment.
Noted a few things but nothing merge-blocking. Thanks for this!
| return get_type_hints(func).get("return") is MsgGenerator | ||
| try: | ||
| return get_type_hints(func).get("return") is MsgGenerator | ||
| except TypeError: |
There was a problem hiding this comment.
What would cause a TypeError here? Mind putting in a comment?
There was a problem hiding this comment.
>>> from typing import Union, get_type_hints
>>> get_type_hints(Union)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/scratch/usr/lib/python3.11/typing.py", line 2330, in get_type_hints
raise TypeError('{!r} is not a module, class, method, '
TypeError: typing.Union is not a module, class, method, or function.
which means if your startup file imports Union (or Optional), the blueapi worker falls over.
Plans that reference bluesky types need an intermediate step in the deserialisation process to allow them to be referenced by name only. Types in plan signatures are now converted to a runtime generated type that can access the context where the plan will be run allowing pydantic to ensure that devices are present and are of the correct type.
Functions took an instance of context as an argument and were only called from within existing context methods so it makes more sense for them to be instance methods of the BlueskyContext instead of standalone functions.
Proof of concept for more flexible type checking/conversion of device types.
Should in theory fix #119
Not tried passing
Spec[Movable]yet but ifSpecis defined as something likeit should also fix #118