From e7e8a2b1b417e0e3d540ee83d62f46a80ae19f82 Mon Sep 17 00:00:00 2001 From: Qynn Schwaab Date: Wed, 4 Oct 2023 09:04:39 -0400 Subject: [PATCH] fix: rely on get_type_hints to grab CatchAll field --- dataclasses_json/undefined.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/dataclasses_json/undefined.py b/dataclasses_json/undefined.py index 9b358ad2..d896bb79 100644 --- a/dataclasses_json/undefined.py +++ b/dataclasses_json/undefined.py @@ -2,8 +2,9 @@ import dataclasses import functools import inspect +import sys from dataclasses import Field, fields -from typing import Any, Callable, Dict, Optional, Tuple, Union, Type +from typing import Any, Callable, Dict, Optional, Tuple, Union, Type, get_type_hints from enum import Enum from marshmallow.exceptions import ValidationError # type: ignore @@ -246,8 +247,10 @@ def _catch_all_init(self, *args, **kwargs): @staticmethod def _get_catch_all_field(cls) -> Field: + cls_globals = vars(sys.modules[cls.__module__]) + types = get_type_hints(cls, globalns=cls_globals) catch_all_fields = list( - filter(lambda f: f.type == Optional[CatchAllVar], fields(cls))) + filter(lambda f: types[f.name] == Optional[CatchAllVar], fields(cls))) number_of_catch_all_fields = len(catch_all_fields) if number_of_catch_all_fields == 0: raise UndefinedParameterError(