Skip to content

Commit 0a9f4a0

Browse files
committed
get_underlying_type
1 parent c54ebfa commit 0a9f4a0

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
from copy import deepcopy
2-
from typing import _TypedDictMeta
2+
from typing import _TypedDictMeta, _GenericAlias
3+
4+
5+
def get_underlying_type(data):
6+
if type(data) == _GenericAlias:
7+
data.__args__ = [get_underlying_type(x) for x in data.__args__]
8+
elif type(data) == _TypedDictMeta:
9+
data = get_nested_types(data.__annotations__)
10+
return data
311

412

513
def get_nested_types(data):
@@ -8,5 +16,7 @@ def get_nested_types(data):
816
print(type(data[key]))
917
if type(data[key]) == _TypedDictMeta:
1018
data[key] = get_nested_types(data[key].__annotations__)
19+
elif type(data[key]) == _GenericAlias:
20+
data[key] = get_underlying_type(data[key])
1121

1222
return data

0 commit comments

Comments
 (0)