From ce55f13742089d426e4085079981aa9960038606 Mon Sep 17 00:00:00 2001 From: brentyi Date: Sun, 3 Nov 2024 23:34:25 -0800 Subject: [PATCH] fix frozendict for Python 3.8 --- src/tyro/constructors/_struct_spec.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/tyro/constructors/_struct_spec.py b/src/tyro/constructors/_struct_spec.py index e2d78589..e61c89ad 100644 --- a/src/tyro/constructors/_struct_spec.py +++ b/src/tyro/constructors/_struct_spec.py @@ -5,7 +5,15 @@ import enum import sys import warnings -from typing import TYPE_CHECKING, Any, Callable, Dict, Iterable, Sequence, Union +from typing import ( + TYPE_CHECKING, + Any, + Callable, + Dict, + Iterable, + Sequence, + Union, +) from typing_extensions import ( Annotated, @@ -271,7 +279,10 @@ def attrs_rule(info: StructTypeInfo) -> StructConstructorSpec | None: @registry.struct_rule def dict_rule(info: StructTypeInfo) -> StructConstructorSpec | None: - if is_typeddict(info.type) or not isinstance(info.default, dict): + if is_typeddict(info.type) or get_origin(info.type) not in ( + dict, + collections.abc.Mapping, + ): return None if info.default in MISSING_SINGLETONS or len(info.default) == 0: