deep-apply 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- deep_apply-1.0.0/LICENSE +21 -0
- deep_apply-1.0.0/PKG-INFO +147 -0
- deep_apply-1.0.0/README.md +115 -0
- deep_apply-1.0.0/deep_apply/__init__.py +1 -0
- deep_apply-1.0.0/deep_apply/deep_apply.py +66 -0
- deep_apply-1.0.0/deep_apply/exceptions.py +2 -0
- deep_apply-1.0.0/deep_apply/handlers/__init__.py +0 -0
- deep_apply-1.0.0/deep_apply/handlers/handle_dict.py +22 -0
- deep_apply-1.0.0/deep_apply/handlers/handle_list.py +17 -0
- deep_apply-1.0.0/deep_apply/handlers/handle_pydantic.py +28 -0
- deep_apply-1.0.0/deep_apply/handlers/handle_set.py +22 -0
- deep_apply-1.0.0/deep_apply/handlers/handle_tuple.py +20 -0
- deep_apply-1.0.0/deep_apply/utils.py +56 -0
- deep_apply-1.0.0/deep_apply.egg-info/PKG-INFO +147 -0
- deep_apply-1.0.0/deep_apply.egg-info/SOURCES.txt +25 -0
- deep_apply-1.0.0/deep_apply.egg-info/dependency_links.txt +1 -0
- deep_apply-1.0.0/deep_apply.egg-info/requires.txt +1 -0
- deep_apply-1.0.0/deep_apply.egg-info/top_level.txt +2 -0
- deep_apply-1.0.0/setup.cfg +8 -0
- deep_apply-1.0.0/setup.py +48 -0
- deep_apply-1.0.0/tests/__init__.py +0 -0
- deep_apply-1.0.0/tests/test_dict.py +70 -0
- deep_apply-1.0.0/tests/test_list.py +68 -0
- deep_apply-1.0.0/tests/test_pydantic.py +76 -0
- deep_apply-1.0.0/tests/test_set.py +68 -0
- deep_apply-1.0.0/tests/test_tuple.py +68 -0
deep_apply-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Zairon Jacobs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: deep-apply
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Deep traverse through an object and apply a function on its values.
|
|
5
|
+
Home-page: https://github.com/zaironjacobs/deep-apply
|
|
6
|
+
Download-URL: https://github.com/zaironjacobs/deep-apply/archive/v1.0.0.tar.gz
|
|
7
|
+
Author: Zairon Jacobs
|
|
8
|
+
Author-email: zaironjacobs@gmail.com
|
|
9
|
+
License: MIT
|
|
10
|
+
Keywords: deep,traverse,apply,object,list,set,tuple,pydantic,dict
|
|
11
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Natural Language :: English
|
|
17
|
+
Requires-Python: >=3.11
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Requires-Dist: pydantic>=2.4.0
|
|
21
|
+
Dynamic: author
|
|
22
|
+
Dynamic: author-email
|
|
23
|
+
Dynamic: classifier
|
|
24
|
+
Dynamic: description
|
|
25
|
+
Dynamic: download-url
|
|
26
|
+
Dynamic: home-page
|
|
27
|
+
Dynamic: keywords
|
|
28
|
+
Dynamic: license
|
|
29
|
+
Dynamic: requires-dist
|
|
30
|
+
Dynamic: requires-python
|
|
31
|
+
Dynamic: summary
|
|
32
|
+
|
|
33
|
+
# Deep Apply
|
|
34
|
+
|
|
35
|
+
[](https://pypi.python.org/pypi/deep-apply)
|
|
36
|
+
[](https://pypi.python.org/pypi/deep-apply)
|
|
37
|
+
[](https://pypi.python.org/pypi/deep-apply)
|
|
38
|
+
|
|
39
|
+
[](https://github.com/zaironjacobs/deep-apply/actions/workflows/test.yml)
|
|
40
|
+
|
|
41
|
+
Deep traverse through an object and apply a function on its values.
|
|
42
|
+
|
|
43
|
+
Supports the following objects:
|
|
44
|
+
|
|
45
|
+
* Dictionaries
|
|
46
|
+
* Lists
|
|
47
|
+
* Sets
|
|
48
|
+
* Tuples
|
|
49
|
+
* Pydantic models
|
|
50
|
+
|
|
51
|
+
### Install
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
pip install deep-apply
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Usage
|
|
58
|
+
|
|
59
|
+
#### Apply upper() on values
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
import deep_apply
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
# 1. Create your callback function. Will call upper() on strings.
|
|
66
|
+
def to_upper(value, **kwargs):
|
|
67
|
+
"""
|
|
68
|
+
To uppercase.
|
|
69
|
+
"""
|
|
70
|
+
|
|
71
|
+
# Apply upper() and return the value
|
|
72
|
+
if isinstance(value, str):
|
|
73
|
+
return value.upper()
|
|
74
|
+
|
|
75
|
+
return value
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
# 2. Your data.
|
|
79
|
+
data = [
|
|
80
|
+
{
|
|
81
|
+
"id": "pZnZMffPCpJx",
|
|
82
|
+
"name": "John Doe",
|
|
83
|
+
"hobbies": {
|
|
84
|
+
"id": "OlVZysGsIywW",
|
|
85
|
+
"sport": ["football", "tennis"],
|
|
86
|
+
"music": ["singing", "guitar", "piano"],
|
|
87
|
+
},
|
|
88
|
+
}
|
|
89
|
+
]
|
|
90
|
+
|
|
91
|
+
# 3. Run apply()
|
|
92
|
+
data = deep_apply.apply(data=data, func=to_upper)
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
#### Result
|
|
96
|
+
|
|
97
|
+
```json
|
|
98
|
+
[
|
|
99
|
+
{
|
|
100
|
+
"id": "PZNZMFFPCPJX",
|
|
101
|
+
"name": "JOHN DOE",
|
|
102
|
+
"hobbies": {
|
|
103
|
+
"id": "OLVZYSGSIYWW",
|
|
104
|
+
"sport": [
|
|
105
|
+
"FOOTBALL",
|
|
106
|
+
"TENNIS"
|
|
107
|
+
],
|
|
108
|
+
"music": [
|
|
109
|
+
"SINGING",
|
|
110
|
+
"GUITAR",
|
|
111
|
+
"PIANO"
|
|
112
|
+
]
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
]
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Ignore keys
|
|
119
|
+
|
|
120
|
+
You can get the current `key` or the current `depth` from `**kwargs` and add a condition e.g. to skip a specific key
|
|
121
|
+
everywhere.
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
def to_upper(value, **kwargs):
|
|
125
|
+
"""
|
|
126
|
+
To uppercase.
|
|
127
|
+
"""
|
|
128
|
+
|
|
129
|
+
key = kwargs.get("key")
|
|
130
|
+
depth = kwargs.get("depth")
|
|
131
|
+
|
|
132
|
+
ignore = False
|
|
133
|
+
|
|
134
|
+
# Ignore the key/field id everywhere (dictionaries or pydantic models)
|
|
135
|
+
if key == "id":
|
|
136
|
+
ignore = True
|
|
137
|
+
|
|
138
|
+
# Ignore the list of music found under hobbies
|
|
139
|
+
elif depth == "hobbies:music":
|
|
140
|
+
ignore = True
|
|
141
|
+
|
|
142
|
+
# Apply upper() and return the value
|
|
143
|
+
if not ignore and isinstance(value, str):
|
|
144
|
+
return value.upper()
|
|
145
|
+
|
|
146
|
+
return value
|
|
147
|
+
```
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# Deep Apply
|
|
2
|
+
|
|
3
|
+
[](https://pypi.python.org/pypi/deep-apply)
|
|
4
|
+
[](https://pypi.python.org/pypi/deep-apply)
|
|
5
|
+
[](https://pypi.python.org/pypi/deep-apply)
|
|
6
|
+
|
|
7
|
+
[](https://github.com/zaironjacobs/deep-apply/actions/workflows/test.yml)
|
|
8
|
+
|
|
9
|
+
Deep traverse through an object and apply a function on its values.
|
|
10
|
+
|
|
11
|
+
Supports the following objects:
|
|
12
|
+
|
|
13
|
+
* Dictionaries
|
|
14
|
+
* Lists
|
|
15
|
+
* Sets
|
|
16
|
+
* Tuples
|
|
17
|
+
* Pydantic models
|
|
18
|
+
|
|
19
|
+
### Install
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pip install deep-apply
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Usage
|
|
26
|
+
|
|
27
|
+
#### Apply upper() on values
|
|
28
|
+
|
|
29
|
+
```python
|
|
30
|
+
import deep_apply
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
# 1. Create your callback function. Will call upper() on strings.
|
|
34
|
+
def to_upper(value, **kwargs):
|
|
35
|
+
"""
|
|
36
|
+
To uppercase.
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
# Apply upper() and return the value
|
|
40
|
+
if isinstance(value, str):
|
|
41
|
+
return value.upper()
|
|
42
|
+
|
|
43
|
+
return value
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
# 2. Your data.
|
|
47
|
+
data = [
|
|
48
|
+
{
|
|
49
|
+
"id": "pZnZMffPCpJx",
|
|
50
|
+
"name": "John Doe",
|
|
51
|
+
"hobbies": {
|
|
52
|
+
"id": "OlVZysGsIywW",
|
|
53
|
+
"sport": ["football", "tennis"],
|
|
54
|
+
"music": ["singing", "guitar", "piano"],
|
|
55
|
+
},
|
|
56
|
+
}
|
|
57
|
+
]
|
|
58
|
+
|
|
59
|
+
# 3. Run apply()
|
|
60
|
+
data = deep_apply.apply(data=data, func=to_upper)
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
#### Result
|
|
64
|
+
|
|
65
|
+
```json
|
|
66
|
+
[
|
|
67
|
+
{
|
|
68
|
+
"id": "PZNZMFFPCPJX",
|
|
69
|
+
"name": "JOHN DOE",
|
|
70
|
+
"hobbies": {
|
|
71
|
+
"id": "OLVZYSGSIYWW",
|
|
72
|
+
"sport": [
|
|
73
|
+
"FOOTBALL",
|
|
74
|
+
"TENNIS"
|
|
75
|
+
],
|
|
76
|
+
"music": [
|
|
77
|
+
"SINGING",
|
|
78
|
+
"GUITAR",
|
|
79
|
+
"PIANO"
|
|
80
|
+
]
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
]
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Ignore keys
|
|
87
|
+
|
|
88
|
+
You can get the current `key` or the current `depth` from `**kwargs` and add a condition e.g. to skip a specific key
|
|
89
|
+
everywhere.
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
def to_upper(value, **kwargs):
|
|
93
|
+
"""
|
|
94
|
+
To uppercase.
|
|
95
|
+
"""
|
|
96
|
+
|
|
97
|
+
key = kwargs.get("key")
|
|
98
|
+
depth = kwargs.get("depth")
|
|
99
|
+
|
|
100
|
+
ignore = False
|
|
101
|
+
|
|
102
|
+
# Ignore the key/field id everywhere (dictionaries or pydantic models)
|
|
103
|
+
if key == "id":
|
|
104
|
+
ignore = True
|
|
105
|
+
|
|
106
|
+
# Ignore the list of music found under hobbies
|
|
107
|
+
elif depth == "hobbies:music":
|
|
108
|
+
ignore = True
|
|
109
|
+
|
|
110
|
+
# Apply upper() and return the value
|
|
111
|
+
if not ignore and isinstance(value, str):
|
|
112
|
+
return value.upper()
|
|
113
|
+
|
|
114
|
+
return value
|
|
115
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from deep_apply.deep_apply import apply
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import copy
|
|
2
|
+
from typing import Callable, TypeVar
|
|
3
|
+
|
|
4
|
+
from deep_apply import utils
|
|
5
|
+
from deep_apply.handlers.handle_dict import handle_dict
|
|
6
|
+
from deep_apply.handlers.handle_list import handle_list
|
|
7
|
+
from deep_apply.handlers.handle_pydantic import handle_pydantic_model
|
|
8
|
+
from deep_apply.handlers.handle_set import handle_set
|
|
9
|
+
from deep_apply.handlers.handle_tuple import handle_tuple
|
|
10
|
+
|
|
11
|
+
T = TypeVar("T")
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def __apply(
|
|
15
|
+
**kwargs,
|
|
16
|
+
) -> T:
|
|
17
|
+
"""
|
|
18
|
+
Apply.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
data = kwargs["data"]
|
|
22
|
+
apply_func: Callable = kwargs["apply_func"]
|
|
23
|
+
key: str | None = kwargs.get("key")
|
|
24
|
+
depth: str | None = kwargs.get("depth")
|
|
25
|
+
|
|
26
|
+
if utils.is_list(data):
|
|
27
|
+
return handle_list(__apply, **kwargs)
|
|
28
|
+
|
|
29
|
+
elif utils.is_set(data):
|
|
30
|
+
return handle_set(__apply, **kwargs)
|
|
31
|
+
|
|
32
|
+
elif utils.is_tuple(data):
|
|
33
|
+
return handle_tuple(__apply, **kwargs)
|
|
34
|
+
|
|
35
|
+
elif utils.is_dict(data):
|
|
36
|
+
return handle_dict(__apply, **kwargs)
|
|
37
|
+
|
|
38
|
+
elif utils.is_pydantic_model(data):
|
|
39
|
+
return handle_pydantic_model(__apply, **kwargs)
|
|
40
|
+
|
|
41
|
+
else:
|
|
42
|
+
return apply_func(data, **{"key": key, "depth": depth})
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def apply(
|
|
46
|
+
data: T,
|
|
47
|
+
func: Callable,
|
|
48
|
+
) -> T:
|
|
49
|
+
"""
|
|
50
|
+
Deep traverse through an object and apply a function on its values.
|
|
51
|
+
|
|
52
|
+
Supports the following objects:
|
|
53
|
+
* Dictionaries
|
|
54
|
+
* Lists
|
|
55
|
+
* Sets
|
|
56
|
+
* Tuples
|
|
57
|
+
* Pydantic models
|
|
58
|
+
|
|
59
|
+
:param data: The data.
|
|
60
|
+
:param func: Function to apply on values.
|
|
61
|
+
"""
|
|
62
|
+
|
|
63
|
+
return __apply(
|
|
64
|
+
data=copy.deepcopy(data),
|
|
65
|
+
apply_func=func,
|
|
66
|
+
)
|
|
File without changes
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
from typing import Callable
|
|
2
|
+
|
|
3
|
+
from deep_apply import utils
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def handle_dict(apply: Callable, **kwargs) -> dict:
|
|
7
|
+
"""
|
|
8
|
+
Handle dict.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
data = kwargs["data"]
|
|
12
|
+
depth: str | None = kwargs.get("depth")
|
|
13
|
+
|
|
14
|
+
for key, value in data.items():
|
|
15
|
+
kwargs["key"] = key
|
|
16
|
+
kwargs["data"] = value
|
|
17
|
+
kwargs["depth"] = utils.set_current_depth(key=key, depth=depth)
|
|
18
|
+
data[key] = apply(
|
|
19
|
+
**kwargs,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
return data
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from typing import Callable
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def handle_list(apply: Callable, **kwargs) -> list:
|
|
5
|
+
"""
|
|
6
|
+
Handle list.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
data = kwargs["data"]
|
|
10
|
+
|
|
11
|
+
for index, value in enumerate(data):
|
|
12
|
+
kwargs["data"] = value
|
|
13
|
+
data[index] = apply(
|
|
14
|
+
**kwargs,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
return data
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
from typing import Callable
|
|
2
|
+
|
|
3
|
+
from pydantic import BaseModel
|
|
4
|
+
|
|
5
|
+
from deep_apply import utils
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def handle_pydantic_model(apply: Callable, **kwargs) -> BaseModel:
|
|
9
|
+
"""
|
|
10
|
+
Handle pydantic model.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
data = kwargs["data"]
|
|
14
|
+
depth: str | None = kwargs.get("depth")
|
|
15
|
+
|
|
16
|
+
for key, value in iter(data):
|
|
17
|
+
kwargs["key"] = key
|
|
18
|
+
kwargs["data"] = value
|
|
19
|
+
kwargs["depth"] = utils.set_current_depth(key=key, depth=depth)
|
|
20
|
+
setattr(
|
|
21
|
+
data,
|
|
22
|
+
key,
|
|
23
|
+
apply(
|
|
24
|
+
**kwargs,
|
|
25
|
+
),
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
return data
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
from typing import Callable
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def handle_set(apply: Callable, **kwargs) -> set:
|
|
5
|
+
"""
|
|
6
|
+
Handle set.
|
|
7
|
+
|
|
8
|
+
The set values will not be modified with the apply function.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
data = kwargs["data"]
|
|
12
|
+
data = list(data)
|
|
13
|
+
|
|
14
|
+
for index, value in enumerate(data):
|
|
15
|
+
kwargs["data"] = value
|
|
16
|
+
data[index] = apply(
|
|
17
|
+
**kwargs,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
data = set(data)
|
|
21
|
+
|
|
22
|
+
return data
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
from typing import Callable
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def handle_tuple(apply: Callable, **kwargs) -> tuple:
|
|
5
|
+
"""
|
|
6
|
+
Handle tuple.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
data = kwargs["data"]
|
|
10
|
+
data = list(data)
|
|
11
|
+
|
|
12
|
+
for index, value in enumerate(data):
|
|
13
|
+
kwargs["data"] = value
|
|
14
|
+
data[index] = apply(
|
|
15
|
+
**kwargs,
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
data = tuple(data)
|
|
19
|
+
|
|
20
|
+
return data
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
from typing import Any
|
|
2
|
+
|
|
3
|
+
from pydantic import BaseModel
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def is_dict(data: Any) -> bool:
|
|
7
|
+
"""
|
|
8
|
+
Check if data type is dict.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
return isinstance(data, dict)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def is_list(data: Any) -> bool:
|
|
15
|
+
"""
|
|
16
|
+
Check if data type is list.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
return isinstance(data, list)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def is_set(data: Any) -> bool:
|
|
23
|
+
"""
|
|
24
|
+
Check if data type is set.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
return isinstance(data, set)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def is_tuple(data: Any) -> bool:
|
|
31
|
+
"""
|
|
32
|
+
Check if data type is tuple.
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
return isinstance(data, tuple)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def is_pydantic_model(data: Any) -> bool:
|
|
39
|
+
"""
|
|
40
|
+
Check if data is a pydantic model.
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
return isinstance(data, BaseModel)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def set_current_depth(key: str, depth: str | None) -> str:
|
|
47
|
+
"""
|
|
48
|
+
Set current depth.
|
|
49
|
+
"""
|
|
50
|
+
|
|
51
|
+
if depth:
|
|
52
|
+
current_depth = f"{depth}:{key}"
|
|
53
|
+
else:
|
|
54
|
+
current_depth = key
|
|
55
|
+
|
|
56
|
+
return current_depth
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: deep-apply
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Deep traverse through an object and apply a function on its values.
|
|
5
|
+
Home-page: https://github.com/zaironjacobs/deep-apply
|
|
6
|
+
Download-URL: https://github.com/zaironjacobs/deep-apply/archive/v1.0.0.tar.gz
|
|
7
|
+
Author: Zairon Jacobs
|
|
8
|
+
Author-email: zaironjacobs@gmail.com
|
|
9
|
+
License: MIT
|
|
10
|
+
Keywords: deep,traverse,apply,object,list,set,tuple,pydantic,dict
|
|
11
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Natural Language :: English
|
|
17
|
+
Requires-Python: >=3.11
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Requires-Dist: pydantic>=2.4.0
|
|
21
|
+
Dynamic: author
|
|
22
|
+
Dynamic: author-email
|
|
23
|
+
Dynamic: classifier
|
|
24
|
+
Dynamic: description
|
|
25
|
+
Dynamic: download-url
|
|
26
|
+
Dynamic: home-page
|
|
27
|
+
Dynamic: keywords
|
|
28
|
+
Dynamic: license
|
|
29
|
+
Dynamic: requires-dist
|
|
30
|
+
Dynamic: requires-python
|
|
31
|
+
Dynamic: summary
|
|
32
|
+
|
|
33
|
+
# Deep Apply
|
|
34
|
+
|
|
35
|
+
[](https://pypi.python.org/pypi/deep-apply)
|
|
36
|
+
[](https://pypi.python.org/pypi/deep-apply)
|
|
37
|
+
[](https://pypi.python.org/pypi/deep-apply)
|
|
38
|
+
|
|
39
|
+
[](https://github.com/zaironjacobs/deep-apply/actions/workflows/test.yml)
|
|
40
|
+
|
|
41
|
+
Deep traverse through an object and apply a function on its values.
|
|
42
|
+
|
|
43
|
+
Supports the following objects:
|
|
44
|
+
|
|
45
|
+
* Dictionaries
|
|
46
|
+
* Lists
|
|
47
|
+
* Sets
|
|
48
|
+
* Tuples
|
|
49
|
+
* Pydantic models
|
|
50
|
+
|
|
51
|
+
### Install
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
pip install deep-apply
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Usage
|
|
58
|
+
|
|
59
|
+
#### Apply upper() on values
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
import deep_apply
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
# 1. Create your callback function. Will call upper() on strings.
|
|
66
|
+
def to_upper(value, **kwargs):
|
|
67
|
+
"""
|
|
68
|
+
To uppercase.
|
|
69
|
+
"""
|
|
70
|
+
|
|
71
|
+
# Apply upper() and return the value
|
|
72
|
+
if isinstance(value, str):
|
|
73
|
+
return value.upper()
|
|
74
|
+
|
|
75
|
+
return value
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
# 2. Your data.
|
|
79
|
+
data = [
|
|
80
|
+
{
|
|
81
|
+
"id": "pZnZMffPCpJx",
|
|
82
|
+
"name": "John Doe",
|
|
83
|
+
"hobbies": {
|
|
84
|
+
"id": "OlVZysGsIywW",
|
|
85
|
+
"sport": ["football", "tennis"],
|
|
86
|
+
"music": ["singing", "guitar", "piano"],
|
|
87
|
+
},
|
|
88
|
+
}
|
|
89
|
+
]
|
|
90
|
+
|
|
91
|
+
# 3. Run apply()
|
|
92
|
+
data = deep_apply.apply(data=data, func=to_upper)
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
#### Result
|
|
96
|
+
|
|
97
|
+
```json
|
|
98
|
+
[
|
|
99
|
+
{
|
|
100
|
+
"id": "PZNZMFFPCPJX",
|
|
101
|
+
"name": "JOHN DOE",
|
|
102
|
+
"hobbies": {
|
|
103
|
+
"id": "OLVZYSGSIYWW",
|
|
104
|
+
"sport": [
|
|
105
|
+
"FOOTBALL",
|
|
106
|
+
"TENNIS"
|
|
107
|
+
],
|
|
108
|
+
"music": [
|
|
109
|
+
"SINGING",
|
|
110
|
+
"GUITAR",
|
|
111
|
+
"PIANO"
|
|
112
|
+
]
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
]
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Ignore keys
|
|
119
|
+
|
|
120
|
+
You can get the current `key` or the current `depth` from `**kwargs` and add a condition e.g. to skip a specific key
|
|
121
|
+
everywhere.
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
def to_upper(value, **kwargs):
|
|
125
|
+
"""
|
|
126
|
+
To uppercase.
|
|
127
|
+
"""
|
|
128
|
+
|
|
129
|
+
key = kwargs.get("key")
|
|
130
|
+
depth = kwargs.get("depth")
|
|
131
|
+
|
|
132
|
+
ignore = False
|
|
133
|
+
|
|
134
|
+
# Ignore the key/field id everywhere (dictionaries or pydantic models)
|
|
135
|
+
if key == "id":
|
|
136
|
+
ignore = True
|
|
137
|
+
|
|
138
|
+
# Ignore the list of music found under hobbies
|
|
139
|
+
elif depth == "hobbies:music":
|
|
140
|
+
ignore = True
|
|
141
|
+
|
|
142
|
+
# Apply upper() and return the value
|
|
143
|
+
if not ignore and isinstance(value, str):
|
|
144
|
+
return value.upper()
|
|
145
|
+
|
|
146
|
+
return value
|
|
147
|
+
```
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
setup.cfg
|
|
4
|
+
setup.py
|
|
5
|
+
deep_apply/__init__.py
|
|
6
|
+
deep_apply/deep_apply.py
|
|
7
|
+
deep_apply/exceptions.py
|
|
8
|
+
deep_apply/utils.py
|
|
9
|
+
deep_apply.egg-info/PKG-INFO
|
|
10
|
+
deep_apply.egg-info/SOURCES.txt
|
|
11
|
+
deep_apply.egg-info/dependency_links.txt
|
|
12
|
+
deep_apply.egg-info/requires.txt
|
|
13
|
+
deep_apply.egg-info/top_level.txt
|
|
14
|
+
deep_apply/handlers/__init__.py
|
|
15
|
+
deep_apply/handlers/handle_dict.py
|
|
16
|
+
deep_apply/handlers/handle_list.py
|
|
17
|
+
deep_apply/handlers/handle_pydantic.py
|
|
18
|
+
deep_apply/handlers/handle_set.py
|
|
19
|
+
deep_apply/handlers/handle_tuple.py
|
|
20
|
+
tests/__init__.py
|
|
21
|
+
tests/test_dict.py
|
|
22
|
+
tests/test_list.py
|
|
23
|
+
tests/test_pydantic.py
|
|
24
|
+
tests/test_set.py
|
|
25
|
+
tests/test_tuple.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pydantic>=2.4.0
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
from setuptools import setup
|
|
2
|
+
from setuptools import find_packages
|
|
3
|
+
|
|
4
|
+
name = "deep-apply"
|
|
5
|
+
version = "1.0.0"
|
|
6
|
+
|
|
7
|
+
with open("README.md", "r") as fh:
|
|
8
|
+
long_description = fh.read()
|
|
9
|
+
|
|
10
|
+
requires = ["pydantic>=2.4.0"]
|
|
11
|
+
|
|
12
|
+
setup(
|
|
13
|
+
name=name,
|
|
14
|
+
version=version,
|
|
15
|
+
author="Zairon Jacobs",
|
|
16
|
+
author_email="zaironjacobs@gmail.com",
|
|
17
|
+
description=(
|
|
18
|
+
"""
|
|
19
|
+
Deep traverse through an object and apply a function on its values.
|
|
20
|
+
"""
|
|
21
|
+
),
|
|
22
|
+
long_description=long_description,
|
|
23
|
+
url="https://github.com/zaironjacobs/deep-apply",
|
|
24
|
+
download_url=f"https://github.com/zaironjacobs/deep-apply/archive/v{version}.tar.gz",
|
|
25
|
+
keywords=[
|
|
26
|
+
"deep",
|
|
27
|
+
"traverse",
|
|
28
|
+
"apply",
|
|
29
|
+
"object",
|
|
30
|
+
"list",
|
|
31
|
+
"set",
|
|
32
|
+
"tuple",
|
|
33
|
+
"pydantic",
|
|
34
|
+
"dict",
|
|
35
|
+
],
|
|
36
|
+
packages=find_packages(),
|
|
37
|
+
install_requires=requires,
|
|
38
|
+
license="MIT",
|
|
39
|
+
classifiers=[
|
|
40
|
+
"Development Status :: 5 - Production/Stable",
|
|
41
|
+
"Intended Audience :: Developers",
|
|
42
|
+
"License :: OSI Approved :: MIT License",
|
|
43
|
+
"Operating System :: OS Independent",
|
|
44
|
+
"Programming Language :: Python :: 3.11",
|
|
45
|
+
"Natural Language :: English",
|
|
46
|
+
],
|
|
47
|
+
python_requires=">=3.11",
|
|
48
|
+
)
|
|
File without changes
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
from pydantic import BaseModel
|
|
2
|
+
|
|
3
|
+
from deep_apply import apply
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def my_func(value: str, **kwargs):
|
|
7
|
+
return value.upper()
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
dict_test = {"first_name": "John", "last_name": "Doe"}
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def test_dict():
|
|
14
|
+
data = dict_test
|
|
15
|
+
data = apply(
|
|
16
|
+
data=data,
|
|
17
|
+
func=my_func,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
assert data["first_name"] == "JOHN" and data["last_name"] == "DOE"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
##########
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def test_dict_in_pydantic():
|
|
27
|
+
class Person(BaseModel):
|
|
28
|
+
nickname: dict[str, str]
|
|
29
|
+
|
|
30
|
+
person = Person(nickname={"nickname": "Johnnie"})
|
|
31
|
+
|
|
32
|
+
data = person
|
|
33
|
+
data = apply(
|
|
34
|
+
data=data,
|
|
35
|
+
func=my_func,
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
assert data.nickname["nickname"] == "JOHNNIE"
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def test_dict_in_dict():
|
|
42
|
+
data = {"person": dict_test}
|
|
43
|
+
data = apply(
|
|
44
|
+
data=data,
|
|
45
|
+
func=my_func,
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
assert (
|
|
49
|
+
data["person"]["first_name"] == "JOHN" and data["person"]["last_name"] == "DOE"
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def test_dict_in_list():
|
|
54
|
+
data = [dict_test]
|
|
55
|
+
data = apply(
|
|
56
|
+
data=data,
|
|
57
|
+
func=my_func,
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
assert data[0]["first_name"] == "JOHN" and data[0]["last_name"] == "DOE"
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def test_dict_in_tuple():
|
|
64
|
+
data = (dict_test, "dummy_data")
|
|
65
|
+
data = apply(
|
|
66
|
+
data=data,
|
|
67
|
+
func=my_func,
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
assert data[0]["first_name"] == "JOHN" and data[0]["last_name"] == "DOE"
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
from pydantic import BaseModel
|
|
2
|
+
|
|
3
|
+
from deep_apply import apply
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def my_func(value: str, **kwargs):
|
|
7
|
+
return value.upper()
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
list_test = ["John Doe"]
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def test_list():
|
|
14
|
+
data = list_test
|
|
15
|
+
data = apply(
|
|
16
|
+
data=data,
|
|
17
|
+
func=my_func,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
assert data[0] == "JOHN DOE"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
##########
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def test_list_in_pydantic():
|
|
27
|
+
class Person(BaseModel):
|
|
28
|
+
nicknames: list[str]
|
|
29
|
+
|
|
30
|
+
person = Person(nicknames=["Johnnie", "Jo"])
|
|
31
|
+
|
|
32
|
+
data = person
|
|
33
|
+
data = apply(
|
|
34
|
+
data=data,
|
|
35
|
+
func=my_func,
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
assert data.nicknames[0] == "JOHNNIE" and data.nicknames[1] == "JO"
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def test_list_in_dict():
|
|
42
|
+
data = {"person": list_test}
|
|
43
|
+
data = apply(
|
|
44
|
+
data=data,
|
|
45
|
+
func=my_func,
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
assert data["person"][0] == "JOHN DOE"
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def test_list_in_list():
|
|
52
|
+
data = [list_test]
|
|
53
|
+
data = apply(
|
|
54
|
+
data=data,
|
|
55
|
+
func=my_func,
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
assert data[0][0] == "JOHN DOE"
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def test_list_in_tuple():
|
|
62
|
+
data = (list_test, "dummy_data")
|
|
63
|
+
data = apply(
|
|
64
|
+
data=data,
|
|
65
|
+
func=my_func,
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
assert data[0][0] == "JOHN DOE"
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
from pydantic import BaseModel
|
|
2
|
+
|
|
3
|
+
from deep_apply import apply
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def my_func(value: str, **kwargs):
|
|
7
|
+
return value.upper()
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Person(BaseModel):
|
|
11
|
+
first_name: str
|
|
12
|
+
last_name: str
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class Child(Person):
|
|
16
|
+
pass
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class Parent(Person):
|
|
20
|
+
child: Child = Child(first_name="Jane", last_name="Doe")
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
parent = Parent(first_name="John", last_name="Doe")
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def test_pydantic():
|
|
27
|
+
data = parent
|
|
28
|
+
data = apply(
|
|
29
|
+
data=data,
|
|
30
|
+
func=my_func,
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
assert data.first_name == "JOHN" and data.last_name == "DOE"
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
##########
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def test_pydantic_in_pydantic():
|
|
40
|
+
data = parent
|
|
41
|
+
data = apply(
|
|
42
|
+
data=data,
|
|
43
|
+
func=my_func,
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
assert data.child.first_name == "JANE" and data.child.last_name == "DOE"
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def test_pydantic_in_dict():
|
|
50
|
+
data = {"person": parent}
|
|
51
|
+
data = apply(
|
|
52
|
+
data=data,
|
|
53
|
+
func=my_func,
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
assert data["person"].first_name == "JOHN" and data["person"].last_name == "DOE"
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def test_pydantic_in_list():
|
|
60
|
+
data = [parent]
|
|
61
|
+
data = apply(
|
|
62
|
+
data=data,
|
|
63
|
+
func=my_func,
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
assert data[0].first_name == "JOHN" and data[0].last_name == "DOE"
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def test_pydantic_in_tuple():
|
|
70
|
+
data = (parent, "dummy_data")
|
|
71
|
+
data = apply(
|
|
72
|
+
data=data,
|
|
73
|
+
func=my_func,
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
assert data[0].first_name == "JOHN" and data[0].last_name == "DOE"
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
from pydantic import BaseModel
|
|
2
|
+
|
|
3
|
+
from deep_apply import apply
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def my_func(value: str, **kwargs):
|
|
7
|
+
return value.upper()
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
set_test: set[str] = {"John Doe"}
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def test_set():
|
|
14
|
+
data = set_test
|
|
15
|
+
data = apply(
|
|
16
|
+
data=data,
|
|
17
|
+
func=my_func,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
assert data.pop() == "JOHN DOE"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
##########
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def test_set_in_pydantic():
|
|
27
|
+
class Person(BaseModel):
|
|
28
|
+
nicknames: set[str]
|
|
29
|
+
|
|
30
|
+
pydantic = Person(nicknames={"Johnnie"})
|
|
31
|
+
|
|
32
|
+
data = pydantic
|
|
33
|
+
data = apply(
|
|
34
|
+
data=data,
|
|
35
|
+
func=my_func,
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
assert data.nicknames.pop() == "JOHNNIE"
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def test_set_in_dict():
|
|
42
|
+
data = {"person": set_test}
|
|
43
|
+
data = apply(
|
|
44
|
+
data=data,
|
|
45
|
+
func=my_func,
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
assert data["person"].pop() == "JOHN DOE"
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def test_set_in_list():
|
|
52
|
+
data = [set_test]
|
|
53
|
+
data = apply(
|
|
54
|
+
data=data,
|
|
55
|
+
func=my_func,
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
assert data[0].pop() == "JOHN DOE"
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def test_set_in_tuple():
|
|
62
|
+
data = (set_test, "dummy_data")
|
|
63
|
+
data = apply(
|
|
64
|
+
data=data,
|
|
65
|
+
func=my_func,
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
assert data[0].pop() == "JOHN DOE"
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
from pydantic import BaseModel
|
|
2
|
+
|
|
3
|
+
from deep_apply import apply
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def my_func(value: str, **kwargs):
|
|
7
|
+
return value.upper()
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
tuple_test: tuple[str, str] = ("John Doe", "Jane Doe")
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def test_tuple():
|
|
14
|
+
data = tuple_test
|
|
15
|
+
data = apply(
|
|
16
|
+
data=data,
|
|
17
|
+
func=my_func,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
assert data[0] == "JOHN DOE" and data[1] == "JANE DOE"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
##########
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def test_tuple_in_pydantic():
|
|
27
|
+
class Person(BaseModel):
|
|
28
|
+
nicknames: tuple[str, str]
|
|
29
|
+
|
|
30
|
+
person = Person(nicknames=("Johnnie", "Jo"))
|
|
31
|
+
|
|
32
|
+
data = person
|
|
33
|
+
data = apply(
|
|
34
|
+
data=data,
|
|
35
|
+
func=my_func,
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
assert data.nicknames[0] == "JOHNNIE" and data.nicknames[1] == "JO"
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def test_tuple_in_dict():
|
|
42
|
+
data = {"person": tuple_test}
|
|
43
|
+
data = apply(
|
|
44
|
+
data=data,
|
|
45
|
+
func=my_func,
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
assert data["person"][0] == "JOHN DOE" and data["person"][1] == "JANE DOE"
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def test_tuple_in_list():
|
|
52
|
+
data = [tuple_test]
|
|
53
|
+
data = apply(
|
|
54
|
+
data=data,
|
|
55
|
+
func=my_func,
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
assert data[0][0] == "JOHN DOE" and data[0][1] == "JANE DOE"
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def test_tuple_in_tuple():
|
|
62
|
+
data = (tuple_test, "dummy_data")
|
|
63
|
+
data = apply(
|
|
64
|
+
data=data,
|
|
65
|
+
func=my_func,
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
assert data[0][0] == "JOHN DOE" and data[0][1] == "JANE DOE"
|