Skip to content

Commit d882c02

Browse files
fix: correct type annotations for ids parameter and test assertions
- Change ids parameter type from list[int] to list[str] in dicttoxml function - Update convert_dict and convert_dict_parallel to accept list[str] | None - Fix test to use string list instead of int list for ids - Add None check in test_parallel.py before type narrowing result_bytes Amp-Thread-ID: https://ampcode.com/threads/T-ab40799c-7282-451b-bdf6-4a74c73a62b7 Co-authored-by: Amp <[email protected]>
1 parent 12a6f77 commit d882c02

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

json2xml/dicttoxml.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ def list2xml_str(
331331

332332
def convert_dict(
333333
obj: dict[str, Any],
334-
ids: list[str],
334+
ids: list[str] | None,
335335
parent: str,
336336
attr_type: bool,
337337
item_func: Callable[[str], str],
@@ -557,7 +557,7 @@ def dicttoxml(
557557
obj: ELEMENT,
558558
root: bool = True,
559559
custom_root: str = "root",
560-
ids: list[int] | None = None,
560+
ids: list[str] | None = None,
561561
attr_type: bool = True,
562562
item_wrap: bool = True,
563563
item_func: Callable[[str], str] = default_item_func,

json2xml/parallel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def _convert_dict_item(
177177

178178
def convert_dict_parallel(
179179
obj: dict[str, Any],
180-
ids: list[str],
180+
ids: list[str] | None,
181181
parent: str,
182182
attr_type: bool,
183183
item_func: Callable[[str], str],

tests/test_dict2xml.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ def test_convert_with_float(self) -> None:
763763
def test_dicttoxml_with_ids(self) -> None:
764764
"""Test dicttoxml with IDs parameter."""
765765
data = {"key": "value"}
766-
result = dicttoxml.dicttoxml(data, ids=[1, 2, 3], attr_type=False)
766+
result = dicttoxml.dicttoxml(data, ids=["1", "2", "3"], attr_type=False)
767767
assert b'<key id="root_' in result
768768
assert b'">value</key>' in result
769769

tests/test_parallel.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ def test_json2xml_parallel_complex(self) -> None:
159159
result_serial = converter_serial.to_xml()
160160

161161
assert result_parallel == result_serial
162-
result_bytes = result_parallel.encode() if isinstance(result_parallel, str) else result_parallel
162+
assert result_parallel is not None
163+
result_bytes: bytes = result_parallel.encode() if isinstance(result_parallel, str) else result_parallel
163164
assert b"<users" in result_bytes
164165
assert b"<total" in result_bytes
165166

0 commit comments

Comments
 (0)