Skip to content

Commit

Permalink
Remove @cache decorator from get_default_value_for_field (#216)
Browse files Browse the repository at this point in the history
* Remove @cache decorator from get_default_value_for_field

* Fix default factory identity test for older Python versions
  • Loading branch information
mciszczon authored Feb 8, 2023
1 parent c076b8c commit 02ee993
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
1 change: 0 additions & 1 deletion dacite/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class DefaultValueNotFoundError(Exception):
pass


@cache
def get_default_value_for_field(field: Field, type_: Type) -> Any:
if field.default != MISSING:
return field.default
Expand Down
15 changes: 14 additions & 1 deletion tests/core/test_base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dataclasses import dataclass, field
from typing import Any, NewType, Optional
from typing import Any, NewType, Optional, List

import pytest

Expand Down Expand Up @@ -191,3 +191,16 @@ class X:
result = from_dict(X, {"s": "test"})

assert result == X(s=MyStr("test"))


def test_dataclass_default_factory_identity():
# https://github.com/konradhalas/dacite/issues/215
@dataclass
class A:
name: str
items: List[str] = field(default_factory=list)

a1 = from_dict(A, {"name": "a1"})
a2 = from_dict(A, {"name": "a2"})

assert a1.items is not a2.items

0 comments on commit 02ee993

Please sign in to comment.