1111from attrs import has as attrs_has
1212
1313from ._compat import (
14+ ANIES ,
1415 FrozenSetSubscriptable ,
1516 Mapping ,
1617 MutableMapping ,
@@ -171,7 +172,7 @@ def __init__(
171172 (lambda t : issubclass (t , Enum ), self ._unstructure_enum ),
172173 (has , self ._unstructure_attrs ),
173174 (is_union_type , self ._unstructure_union ),
174- (lambda t : t is Any , self .unstructure ),
175+ (lambda t : t in ANIES , self .unstructure ),
175176 ]
176177 )
177178
@@ -181,7 +182,10 @@ def __init__(
181182 self ._structure_func = MultiStrategyDispatch (structure_fallback_factory )
182183 self ._structure_func .register_func_list (
183184 [
184- (lambda cl : cl is Any or cl is Optional or cl is None , lambda v , _ : v ),
185+ (
186+ lambda cl : cl in ANIES or cl is Optional or cl is None ,
187+ lambda v , _ : v ,
188+ ),
185189 (is_generic_attrs , self ._gen_structure_generic , True ),
186190 (lambda t : get_newtype_base (t ) is not None , self ._structure_newtype ),
187191 (is_type_alias , self ._find_type_alias_structure_hook , True ),
@@ -545,7 +549,7 @@ def structure_attrs_fromdict(self, obj: Mapping[str, Any], cl: type[T]) -> T:
545549
546550 def _structure_list (self , obj : Iterable [T ], cl : Any ) -> list [T ]:
547551 """Convert an iterable to a potentially generic list."""
548- if is_bare (cl ) or cl .__args__ [0 ] is Any :
552+ if is_bare (cl ) or cl .__args__ [0 ] in ANIES :
549553 res = list (obj )
550554 else :
551555 elem_type = cl .__args__ [0 ]
@@ -575,7 +579,7 @@ def _structure_list(self, obj: Iterable[T], cl: Any) -> list[T]:
575579
576580 def _structure_deque (self , obj : Iterable [T ], cl : Any ) -> deque [T ]:
577581 """Convert an iterable to a potentially generic deque."""
578- if is_bare (cl ) or cl .__args__ [0 ] is Any :
582+ if is_bare (cl ) or cl .__args__ [0 ] in ANIES :
579583 res = deque (e for e in obj )
580584 else :
581585 elem_type = cl .__args__ [0 ]
@@ -607,7 +611,7 @@ def _structure_set(
607611 self , obj : Iterable [T ], cl : Any , structure_to : type = set
608612 ) -> Set [T ]:
609613 """Convert an iterable into a potentially generic set."""
610- if is_bare (cl ) or cl .__args__ [0 ] is Any :
614+ if is_bare (cl ) or cl .__args__ [0 ] in ANIES :
611615 return structure_to (obj )
612616 elem_type = cl .__args__ [0 ]
613617 handler = self ._structure_func .dispatch (elem_type )
@@ -646,10 +650,10 @@ def _structure_dict(self, obj: Mapping[T, V], cl: Any) -> dict[T, V]:
646650 if is_bare (cl ) or cl .__args__ == (Any , Any ):
647651 return dict (obj )
648652 key_type , val_type = cl .__args__
649- if key_type is Any :
653+ if key_type in ANIES :
650654 val_conv = self ._structure_func .dispatch (val_type )
651655 return {k : val_conv (v , val_type ) for k , v in obj .items ()}
652- if val_type is Any :
656+ if val_type in ANIES :
653657 key_conv = self ._structure_func .dispatch (key_type )
654658 return {key_conv (k , key_type ): v for k , v in obj .items ()}
655659 key_conv = self ._structure_func .dispatch (key_type )
@@ -673,7 +677,7 @@ def _structure_tuple(self, obj: Any, tup: type[T]) -> T:
673677 """Deal with structuring into a tuple."""
674678 tup_params = None if tup in (Tuple , tuple ) else tup .__args__
675679 has_ellipsis = tup_params and tup_params [- 1 ] is Ellipsis
676- if tup_params is None or (has_ellipsis and tup_params [0 ] is Any ):
680+ if tup_params is None or (has_ellipsis and tup_params [0 ] in ANIES ):
677681 # Just a Tuple. (No generic information.)
678682 return tuple (obj )
679683 if has_ellipsis :
0 commit comments