From 9ec63f818787544eb709c8890836d56e7b01a8f1 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Sat, 8 Mar 2025 15:49:21 -0500 Subject: [PATCH] Offer a `mods: list` to `dec_type_union()`; drop importing this-mod --- tractor/msg/_exts.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tractor/msg/_exts.py b/tractor/msg/_exts.py index abf7bcd..31eafb5 100644 --- a/tractor/msg/_exts.py +++ b/tractor/msg/_exts.py @@ -33,6 +33,9 @@ converters, |_ https://jcristharif.com/msgspec/changelog.html ''' +from types import ( + ModuleType, +) import typing from typing import ( Type, @@ -41,19 +44,20 @@ from typing import ( def dec_type_union( type_names: list[str], -) -> Type: + mods: list[ModuleType] = [] +) -> Type|Union[Type]: ''' Look up types by name, compile into a list and then create and return a `typing.Union` from the full set. ''' - import importlib + # import importlib types: list[Type] = [] for type_name in type_names: for mod in [ typing, - importlib.import_module(__name__), - ]: + # importlib.import_module(__name__), + ] + mods: if type_ref := getattr( mod, type_name,