Skip to content

Commit

Permalink
fix: rely on get_type_hints to grab CatchAll field
Browse files Browse the repository at this point in the history
  • Loading branch information
2ynn committed Oct 4, 2023
1 parent 5207d26 commit e7e8a2b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions dataclasses_json/undefined.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit e7e8a2b

Please sign in to comment.