Skip to content

Commit 1d0e5ce

Browse files
authored
fix: Use consistent naming for reference type errors (#938)
When running a plan with invalid parameters, the error message would be different depending on whether the required type was generic or not, eg `<class 'bluesky.protocols.Readable'>` vs `bluesky.protocols.Movable[float]` Fixes #934
1 parent 46c39da commit 1d0e5ce

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/blueapi/core/context.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ def qualified_name(target: type) -> str:
6666
return f"{module_name}{name}"
6767

6868

69+
def qualified_generic_name(target: type) -> str:
70+
args = get_args(target)
71+
subscript = (
72+
"[" + ", ".join(qualified_name(arg) for arg in args) + "]" if args else ""
73+
)
74+
return f"{qualified_name(target)}{subscript}"
75+
76+
6977
def is_bluesky_type(typ: type) -> bool:
7078
return typ in BLUESKY_PROTOCOLS or isinstance(typ, BLUESKY_PROTOCOLS)
7179

@@ -251,7 +259,10 @@ def valid(value):
251259
if not val or not is_compatible(
252260
val, cls.origin or target, cls.args
253261
):
254-
raise ValueError(f"Device {value} is not of type {target}")
262+
required = qualified_generic_name(target)
263+
raise ValueError(
264+
f"Device {value} is not of type {required}"
265+
)
255266
return val
256267

257268
return core_schema.no_info_after_validator_function(

0 commit comments

Comments
 (0)