@@ -122,7 +122,7 @@ def _process_annotated(target: type[Any]) -> tuple[Any, tuple[Any, ...]]:
122122    return  target , ()
123123
124124
125- def  _get_target_raw_type (target : type [Any ]) ->  Any :
125+ def  _get_target_raw_type (target : type [Any ]  |   Any ) ->  Any :
126126    """ 
127127    Takes a type like ``Optional[str]`` and returns str, or ``Optional[Dict[str, 
128128    int]]`` and returns dict. Returns Union for a Union with more than one 
@@ -151,12 +151,14 @@ def _get_inner_type(__target: type[Any]) -> type[Any]:
151151    raise  AssertionError (msg )
152152
153153
154- def  _nested_dataclass_to_names (__target : type [Any ], * inner : str ) ->  Iterator [list [str ]]:
154+ def  _nested_dataclass_to_names (
155+     __target : type [Any ] |  Any , * inner : str 
156+ ) ->  Iterator [list [str ]]:
155157    """ 
156158    Yields each entry, like ``("a", "b", "c")`` for ``a.b.c``. 
157159    """ 
158160
159-     if  dataclasses .is_dataclass (__target ):
161+     if  isinstance ( __target ,  type )  and   dataclasses .is_dataclass (__target ):
160162        for  field  in  dataclasses .fields (__target ):
161163            yield  from  _nested_dataclass_to_names (field .type , * inner , field .name )
162164    else :
@@ -194,7 +196,7 @@ def get_item(self, *fields: str, is_dict: bool) -> Any:
194196        ...
195197
196198    @classmethod  
197-     def  convert (cls , item : Any , target : type [Any ]) ->  object :
199+     def  convert (cls , item : Any , target : type [Any ]  |   Any ) ->  object :
198200        """ 
199201        Convert an ``item`` from the base representation of the source's source 
200202        into a ``target`` type. Raises TypeError if the conversion fails. 
@@ -246,7 +248,7 @@ def get_item(
246248        raise  KeyError (msg )
247249
248250    @classmethod  
249-     def  convert (cls , item : str , target : type [Any ]) ->  object :
251+     def  convert (cls , item : str , target : type [Any ]  |   Any ) ->  object :
250252        """ 
251253        Convert an item from the environment (always a string) into a target type. 
252254        """ 
@@ -322,7 +324,7 @@ def _unrecognized_dict(
322324            continue 
323325        (inner_option_field ,) =  matches 
324326        inner_option  =  inner_option_field .type 
325-         if  dataclasses .is_dataclass (inner_option ):
327+         if  isinstance ( inner_option ,  type )  and   dataclasses .is_dataclass (inner_option ):
326328            yield  from  _unrecognized_dict (
327329                settings [keystr ], inner_option , (* above , keystr )
328330            )
@@ -386,7 +388,7 @@ def get_item(
386388
387389    @classmethod  
388390    def  convert (
389-         cls , item : str  |  list [str ] |  dict [str , str ] |  bool , target : type [Any ]
391+         cls , item : str  |  list [str ] |  dict [str , str ] |  bool , target : type [Any ]  |   Any 
390392    ) ->  object :
391393        target , _  =  _process_annotated (target )
392394        raw_target  =  _get_target_raw_type (target )
@@ -484,13 +486,13 @@ def get_item(self, *fields: str, is_dict: bool) -> Any:  # noqa: ARG002
484486            raise  KeyError (msg ) from  None 
485487
486488    @classmethod  
487-     def  convert (cls , item : Any , target : type [Any ]) ->  object :
489+     def  convert (cls , item : Any , target : type [Any ]  |   Any ) ->  object :
488490        """ 
489491        Convert an ``item`` from TOML into a ``target`` type. 
490492        """ 
491493        target , annotations  =  _process_annotated (target )
492494        raw_target  =  _get_target_raw_type (target )
493-         if  dataclasses .is_dataclass (raw_target ):
495+         if  isinstance ( raw_target ,  type )  and   dataclasses .is_dataclass (raw_target ):
494496            fields  =  dataclasses .fields (raw_target )
495497            values  =  ((k .replace ("-" , "_" ), v ) for  k , v  in  item .items ())
496498            return  raw_target (
@@ -579,7 +581,7 @@ def convert_target(self, target: type[T], *prefixes: str) -> T:
579581        errors  =  []
580582        prep : dict [str , Any ] =  {}
581583        for  field  in  dataclasses .fields (target ):  # type: ignore[arg-type] 
582-             if  dataclasses .is_dataclass (field .type ):
584+             if  isinstance ( field . type ,  type )  and   dataclasses .is_dataclass (field .type ):
583585                try :
584586                    prep [field .name ] =  self .convert_target (
585587                        field .type , * prefixes , field .name 
0 commit comments