You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* fix: replace mutable default argument in dicttoxml()
xml_namespaces had a mutable default dict which is a classic Python
footgun where mutations persist across calls. Changed to None with
an 'or {}' guard inside the function body, matching the pattern
already used in dicttoxml_fast.py.
Amp-Thread-ID: https://ampcode.com/threads/T-019d6bf2-ce86-763d-8c62-08118f358cbe
Co-authored-by: Amp <amp@ampcode.com>
* fix: remove unused Dict and List imports from conftest.py
These typing imports were dead code since the file already uses
the built-in dict[...] and list[...] syntax everywhere.
Amp-Thread-ID: https://ampcode.com/threads/T-019d6bf2-ce86-763d-8c62-08118f358cbe
Co-authored-by: Amp <amp@ampcode.com>
* fix: remove dead setUp/tearDown stubs from TestJson2xml
These were unittest-style no-op methods that serve no purpose in
pytest classes.
Amp-Thread-ID: https://ampcode.com/threads/T-019d6bf2-ce86-763d-8c62-08118f358cbe
Co-authored-by: Amp <amp@ampcode.com>
* fix: hoist SystemRandom() to module level in dicttoxml
Avoids creating a new SystemRandom instance on every make_id() call.
The module-level _SAFE_RANDOM is reused across all invocations.
Amp-Thread-ID: https://ampcode.com/threads/T-019d6bf2-ce86-763d-8c62-08118f358cbe
Co-authored-by: Amp <amp@ampcode.com>
* chore: stop tracking coverage data
* Update json2xml/dicttoxml.py
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
* Align Rust list wrapper semantics with Python
* fix: warnings
---------
Co-authored-by: Amp <amp@ampcode.com>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Copy file name to clipboardExpand all lines: lat.md/behavior.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,6 +14,8 @@ Default output includes an XML declaration, wraps content in `all`, pretty print
14
14
15
15
[[json2xml/json2xml.py#Json2xml#to_xml]] calls [[json2xml/dicttoxml.py#dicttoxml]] with the configured wrapper, root, `attr_type`, `item_wrap`, `cdata`, and `list_headers` options. When `item_wrap=False`, list values repeat the parent tag instead of creating `<item>` children. When `pretty=False`, the library returns the serializer bytes directly.
16
16
17
+
The Rust fast path in [[rust/src/lib.rs#write_dict_contents]] and [[rust/src/lib.rs#write_list_contents]] mirrors those Python list-wrapper rules. `list_headers=True` suppresses the outer list container and repeats the parent tag only for nested dict items, while primitive items still use the same scalar tags that Python emits.
18
+
17
19
## XPath 3.1 format
18
20
19
21
XPath mode swaps the project-specific XML shape for the W3C `json-to-xml` mapping with typed element names and the XPath functions namespace.
@@ -24,4 +26,4 @@ When `xpath_format=True`, [[json2xml/dicttoxml.py#dicttoxml]] delegates payload
24
26
25
27
Pretty printing acts as a validation step, because the formatter reparses the generated XML before returning it.
26
28
27
-
[[json2xml/json2xml.py#Json2xml#to_xml]] uses `defusedxml.minidom.parseString` before `toprettyxml`. If the generated bytes are not well-formed XML, the converter raises `InvalidDataError` instead of returning broken pretty output.
29
+
[[json2xml/json2xml.py#Json2xml#to_xml]] uses `defusedxml.minidom.parseString` before `toprettyxml`. If the generated bytes are not well-formed XML, the converter raises `InvalidDataError` instead of returning broken pretty output.
Copy file name to clipboardExpand all lines: lat.md/tests.md
+13-1Lines changed: 13 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,4 +28,16 @@ XPath mode should emit the W3C XPath functions namespace and typed child element
28
28
29
29
### Item-wrap false repeats parent tag
30
30
31
-
Disabling item wrapping should repeat the parent element name for primitive list items instead of producing nested `<item>` tags.
31
+
Disabling item wrapping should repeat the parent element name for primitive list items instead of producing nested `<item>` tags.
32
+
33
+
### Default xml namespaces stay empty
34
+
35
+
Calling `dicttoxml` without `xml_namespaces` should preserve the legacy root output and avoid adding namespace declarations or `xsi:` attributes implicitly.
36
+
37
+
### Explicit xml namespaces emit schema attributes
38
+
39
+
Supplying namespace prefixes and an `xsi` mapping should emit the expected `xmlns:*` declarations plus supported schema attributes without mutating the caller input.
40
+
41
+
### Xml namespace inputs are not mutated across calls
42
+
43
+
Reusing one `xml_namespaces` mapping across multiple `dicttoxml` calls should return identical XML each time so namespace declarations never accumulate on the shared dict.
0 commit comments