mirror of
https://gitlab.com/kupfer/kupferbootstrap.git
synced 2025-02-23 05:35:44 -05:00
dataclass: support UnionType (A | B)
This commit is contained in:
parent
95c2ffd133
commit
07ccc26d95
1 changed files with 2 additions and 1 deletions
|
@ -3,6 +3,7 @@ from __future__ import annotations
|
|||
from dataclasses import dataclass
|
||||
from munch import Munch
|
||||
from typing import ClassVar, Optional, Union, Mapping, Any, get_type_hints, get_origin, get_args, Iterable
|
||||
from types import UnionType
|
||||
|
||||
|
||||
def munchclass(*args, init=False, **kwargs):
|
||||
|
@ -14,7 +15,7 @@ def resolve_type_hint(hint: type) -> Iterable[type]:
|
|||
args: Iterable[type] = get_args(hint)
|
||||
if origin is Optional:
|
||||
args = set(list(args) + [type(None)])
|
||||
if origin in [Union, Optional]:
|
||||
if origin in [Union, UnionType, Optional]:
|
||||
results: list[type] = []
|
||||
for arg in args:
|
||||
results += resolve_type_hint(arg)
|
||||
|
|
Loading…
Add table
Reference in a new issue