Skip to content

Commit 98f72f4

Browse files
authored
Merge branch 'konradhalas:master' into master
2 parents 45db12a + 45c2993 commit 98f72f4

File tree

6 files changed

+31
-7
lines changed

6 files changed

+31
-7
lines changed

CHANGELOG.md

+10-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,15 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
[Unreleased]
8+
## [Unreleased]
99

10-
Nothing yet.
10+
- Fix issues with caching internal function calls
11+
12+
## [1.8.1] - 2023-05-12
13+
14+
### Fixed
15+
16+
- Fix value creation for a field with a default factory
1117

1218
## [1.8.0] - 2023-01-26
1319

@@ -113,7 +119,8 @@ Nothing yet.
113119

114120
- Validate type for generic collection fields
115121

116-
[Unreleased]: https://github.com/konradhalas/dacite/compare/v1.8.0...HEAD
122+
[Unreleased]: https://github.com/konradhalas/dacite/compare/v1.8.1...HEAD
123+
[1.8.1]: https://github.com/konradhalas/dacite/compare/v1.8.0...v1.8.1
117124
[1.8.0]: https://github.com/konradhalas/dacite/compare/v1.7.0...v1.8.0
118125
[1.7.0]: https://github.com/konradhalas/dacite/compare/v1.6.0...v1.7.0
119126
[1.6.0]: https://github.com/konradhalas/dacite/compare/v1.5.1...v1.6.0

dacite/cache.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
@lru_cache(maxsize=None)
1010
def cache(function: T) -> T:
11-
return lru_cache(maxsize=get_cache_size())(function) # type: ignore
11+
return lru_cache(maxsize=get_cache_size(), typed=True)(function) # type: ignore
1212

1313

1414
def set_cache_size(size: Optional[int]) -> None:

dacite/dataclasses.py

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ class DefaultValueNotFoundError(Exception):
1111
pass
1212

1313

14-
@cache
1514
def get_default_value_for_field(field: Field, type_: Type) -> Any:
1615
if field.default != MISSING:
1716
return field.default

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name="dacite",
5-
version="1.8.0",
5+
version="1.8.1",
66
description="Simple creation of data classes from dictionaries.",
77
long_description=open("README.md").read(),
88
long_description_content_type="text/markdown",

tests/core/test_base.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from dataclasses import dataclass, field
2-
from typing import Any, NewType, Optional
2+
from typing import Any, NewType, Optional, List
33

44
import pytest
55

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

193193
assert result == X(s=MyStr("test"))
194+
195+
196+
def test_dataclass_default_factory_identity():
197+
# https://github.com/konradhalas/dacite/issues/215
198+
@dataclass
199+
class A:
200+
name: str
201+
items: List[str] = field(default_factory=list)
202+
203+
a1 = from_dict(A, {"name": "a1"})
204+
a2 = from_dict(A, {"name": "a2"})
205+
206+
assert a1.items is not a2.items

tests/test_types.py

+5
Original file line numberDiff line numberDiff line change
@@ -399,3 +399,8 @@ class FakeType:
399399
_special = True
400400

401401
assert extract_generic(FakeType, defaults) == defaults
402+
403+
404+
def test_optional_and_union_none_does_not_pollute_scope_via_caching():
405+
is_generic(Optional[str])
406+
is_generic_collection(str | None)

0 commit comments

Comments
 (0)