Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/pip/gitpython-3.1.37
Browse files Browse the repository at this point in the history
  • Loading branch information
lidatong authored Jan 12, 2024
2 parents 1db2eaf + c26c3b9 commit b05db79
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dataclasses_json/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class DataClassJsonMixin(abc.ABC):
As with other ABCs, it should not be instantiated directly.
"""
dataclass_json_config = None
dataclass_json_config: Optional[dict] = None

def to_json(self,
*,
Expand Down
8 changes: 7 additions & 1 deletion dataclasses_json/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,13 @@ def handle_pep0673(pre_0673_hint: str) -> Union[Type, str]:
type_args = handle_pep0673(type_args)

if _isinstance_safe(type_args, Collection) and not _issubclass_safe(type_args, Enum):
return list(_decode_item(type_arg, x) for type_arg, x in zip(type_args, xs))
if len(type_args) == len(xs):
return list(_decode_item(type_arg, x) for type_arg, x in zip(type_args, xs))
else:
raise TypeError(f"Number of types specified in the collection type {str(type_args)} "
f"does not match number of elements in the collection. In case you are working with tuples"
f"take a look at this document "
f"docs.python.org/3/library/typing.html#annotating-tuples.")
return list(_decode_item(type_args, x) for x in xs)


Expand Down
2 changes: 1 addition & 1 deletion dataclasses_json/undefined.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def _get_default(catch_all_field: Field) -> Any:
@staticmethod
def handle_to_dict(obj, kvs: Dict[Any, Any]) -> Dict[Any, Any]:
catch_all_field = \
_CatchAllUndefinedParameters._get_catch_all_field(obj)
_CatchAllUndefinedParameters._get_catch_all_field(obj.__class__)
undefined_parameters = kvs.pop(catch_all_field.name)
if isinstance(undefined_parameters, dict):
kvs.update(
Expand Down
20 changes: 19 additions & 1 deletion tests/test_undefined_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,4 +383,22 @@ class UnknownAPIDumpDefault:
catch_all: CatchAll = field(default_factory=dict)

dump = UnknownAPIDumpDefault(**valid_response)
assert dump.catch_all == {}
assert dump.catch_all == {}


def test_undefined_inheritance():
@dataclass_json(undefined=Undefined.INCLUDE)
@dataclass
class TestInternalConfig:
options: CatchAll = None
val: str = "bar"
val2: int = 0

@dataclass_json
@dataclass
class TestInternalExtendConfig(TestInternalConfig):
val: str = "baz"

tie = TestInternalExtendConfig()
tie.to_dict()

0 comments on commit b05db79

Please sign in to comment.