Offer a `mods: list` to `dec_type_union()`; drop importing this-mod
parent
6b65b9e4de
commit
9ec63f8187
|
@ -33,6 +33,9 @@ converters,
|
||||||
|_ https://jcristharif.com/msgspec/changelog.html
|
|_ https://jcristharif.com/msgspec/changelog.html
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
from types import (
|
||||||
|
ModuleType,
|
||||||
|
)
|
||||||
import typing
|
import typing
|
||||||
from typing import (
|
from typing import (
|
||||||
Type,
|
Type,
|
||||||
|
@ -41,19 +44,20 @@ from typing import (
|
||||||
|
|
||||||
def dec_type_union(
|
def dec_type_union(
|
||||||
type_names: list[str],
|
type_names: list[str],
|
||||||
) -> Type:
|
mods: list[ModuleType] = []
|
||||||
|
) -> Type|Union[Type]:
|
||||||
'''
|
'''
|
||||||
Look up types by name, compile into a list and then create and
|
Look up types by name, compile into a list and then create and
|
||||||
return a `typing.Union` from the full set.
|
return a `typing.Union` from the full set.
|
||||||
|
|
||||||
'''
|
'''
|
||||||
import importlib
|
# import importlib
|
||||||
types: list[Type] = []
|
types: list[Type] = []
|
||||||
for type_name in type_names:
|
for type_name in type_names:
|
||||||
for mod in [
|
for mod in [
|
||||||
typing,
|
typing,
|
||||||
importlib.import_module(__name__),
|
# importlib.import_module(__name__),
|
||||||
]:
|
] + mods:
|
||||||
if type_ref := getattr(
|
if type_ref := getattr(
|
||||||
mod,
|
mod,
|
||||||
type_name,
|
type_name,
|
||||||
|
|
Loading…
Reference in New Issue