Skip to content

Commit 625ac9d

Browse files
committed
fixed issue with dictionary collection
1 parent fe732b9 commit 625ac9d

File tree

4 files changed

+53
-3
lines changed

4 files changed

+53
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
1.0.3 - 2022/07/24
2+
* Fixed issue with dictionary collection: https://github.com/anikolaienko/py-automapper/issues/4
3+
14
1.0.2 - 2022/07/24
25
* Bug fix: pass parameters override in MappingWrapper.map
3-
* Added support for mapping fields with different names
6+
* Added support for mapping fields with different names: https://github.com/anikolaienko/py-automapper/issues/3
47

58
1.0.1 - 2022/01/05
69
* Bug fix

automapper/mapper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ def _map_subobject(
237237
k: self._map_subobject(
238238
v, _visited_stack, skip_none_values=skip_none_values
239239
)
240-
for k, v in obj
240+
for k, v in obj.items()
241241
}
242242
else:
243243
result = type(obj)( # type: ignore [call-arg]

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "py-automapper"
3-
version = "1.0.0"
3+
version = "1.0.3"
44
description = "Library for automatically mapping one object to another"
55
authors = ["Andrii Nikolaienko <[email protected]>"]
66
license = "MIT"
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
from copy import deepcopy
2+
from typing import Any, Dict
3+
4+
from automapper import mapper
5+
6+
7+
class Candy:
8+
def __init__(self, name: str, brand: str):
9+
self.name = name
10+
self.brand = brand
11+
12+
13+
class Shop:
14+
def __init__(self, products: Dict[str, Any], annual_income: int):
15+
self.products: Dict[str, Any] = deepcopy(products)
16+
self.annual_income = annual_income
17+
18+
19+
class ShopPublicInfo:
20+
def __init__(self, products: Dict[str, Any]):
21+
self.products: Dict[str, Any] = deepcopy(products)
22+
23+
24+
def test_map__with_dict_field():
25+
products = {
26+
"magazines": ["Forbes", "Time", "The New Yorker"],
27+
"candies": [
28+
Candy("Reese's cups", "The Hershey Company"),
29+
Candy("Snickers", "Mars, Incorporated"),
30+
],
31+
}
32+
shop = Shop(products=products, annual_income=10000000)
33+
34+
public_info = mapper.to(ShopPublicInfo).map(shop)
35+
36+
assert public_info.products["magazines"] == shop.products["magazines"]
37+
assert id(public_info.products["magazines"]) != id(shop.products["magazines"])
38+
39+
assert public_info.products["candies"] != shop.products["candies"]
40+
assert public_info.products["candies"][0] != shop.products["candies"][0]
41+
assert public_info.products["candies"][1] != shop.products["candies"][1]
42+
43+
assert public_info.products["candies"][0].name == "Reese's cups"
44+
assert public_info.products["candies"][0].brand == "The Hershey Company"
45+
46+
assert public_info.products["candies"][1].name == "Snickers"
47+
assert public_info.products["candies"][1].brand == "Mars, Incorporated"

0 commit comments

Comments
 (0)