From b3ca223935e819029f9417620b048ac92ebc43ce Mon Sep 17 00:00:00 2001 From: Peter Holloway Date: Tue, 6 May 2025 14:40:11 +0100 Subject: [PATCH] fix: Use consistent naming for reference type errors --- src/blueapi/core/context.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/blueapi/core/context.py b/src/blueapi/core/context.py index 38a03d7454..ae83494733 100644 --- a/src/blueapi/core/context.py +++ b/src/blueapi/core/context.py @@ -66,6 +66,14 @@ def qualified_name(target: type) -> str: return f"{module_name}{name}" +def qualified_generic_name(target: type) -> str: + args = get_args(target) + subscript = ( + "[" + ", ".join(qualified_name(arg) for arg in args) + "]" if args else "" + ) + return f"{qualified_name(target)}{subscript}" + + def is_bluesky_type(typ: type) -> bool: return typ in BLUESKY_PROTOCOLS or isinstance(typ, BLUESKY_PROTOCOLS) @@ -251,7 +259,10 @@ def valid(value): if not val or not is_compatible( val, cls.origin or target, cls.args ): - raise ValueError(f"Device {value} is not of type {target}") + required = qualified_generic_name(target) + raise ValueError( + f"Device {value} is not of type {required}" + ) return val return core_schema.no_info_after_validator_function(