Skip to content

Commit fa8fb57

Browse files
committed
chore: apply review suggestions
1 parent 1803208 commit fa8fb57

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

‎gitlab/utils.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# You should have received a copy of the GNU Lesser General Public License
1616
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1717

18+
import copy
1819
import pathlib
1920
import traceback
2021
import urllib.parse
@@ -50,7 +51,7 @@ def response_content(
5051

5152

5253
def _transform_types(
53-
data: Dict[str, Any], custom_types: dict, transform_files: Optional[bool] = True
54+
data: Dict[str, Any], custom_types: dict, *, transform_files: Optional[bool] = True
5455
) -> Tuple[dict, dict]:
5556
"""Copy the data dict with attributes that have custom types and transform them
5657
before being sent to the server.
@@ -63,11 +64,11 @@ def _transform_types(
6364
A tuple of the transformed data dict and files dict"""
6465

6566
# Duplicate data to avoid messing with what the user sent us
66-
data = data.copy()
67+
data = copy.deepcopy(data)
6768
files = {}
6869

6970
for attr_name, type_cls in custom_types.items():
70-
if attr_name not in data.keys():
71+
if attr_name not in data:
7172
continue
7273

7374
type_obj = type_cls(data[attr_name])

‎tests/unit/test_utils.py‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,16 @@ def test_warn(self):
9797
assert warn_source == warning.source
9898

9999

100-
def test_transform_types_copies_data():
100+
def test_transform_types_copies_data_with_empty_files():
101101
data = {"attr": "spam"}
102-
new_data, _ = utils._transform_types(data, {})
102+
new_data, files = utils._transform_types(data, {})
103103

104104
assert new_data is not data
105+
assert new_data == data
106+
assert files == {}
105107

106108

107-
def test_transform_types_with_transform_files():
109+
def test_transform_types_with_transform_files_populates_files():
108110
custom_types = {"attr": types.FileAttribute}
109111
data = {"attr": "spam"}
110112
new_data, files = utils._transform_types(data, custom_types)
@@ -113,7 +115,7 @@ def test_transform_types_with_transform_files():
113115
assert files["attr"] == ("attr", "spam")
114116

115117

116-
def test_transform_types_without_transform_files():
118+
def test_transform_types_without_transform_files_populates_data_with_empty_files():
117119
custom_types = {"attr": types.FileAttribute}
118120
data = {"attr": "spam"}
119121
new_data, files = utils._transform_types(data, custom_types, transform_files=False)

0 commit comments

Comments
 (0)