From 12172cc5cd8be52bfdb330457aa58c173664a4c6 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Fri, 9 Jun 2023 14:40:30 -0400 Subject: [PATCH] Make `.data.types.Struct.typecast()` work via type lookup from `builtins` --- piker/data/types.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/piker/data/types.py b/piker/data/types.py index 7a3bc6bb..620182fc 100644 --- a/piker/data/types.py +++ b/piker/data/types.py @@ -18,7 +18,8 @@ Built-in (extension) types. """ -import sys +import builtins +# import sys from pprint import pformat import msgspec @@ -85,5 +86,11 @@ class Struct( self, # fields: list[str] | None = None, ) -> None: - for fname, ftype in self.__annotations__.items(): - setattr(self, fname, ftype(getattr(self, fname))) + for fname, ftype_str in self.__annotations__.items(): + ftype = getattr(builtins, ftype_str) + attr = getattr(self, fname) + setattr( + self, + fname, + ftype(attr), + )