diff --git a/json2xml/dicttoxml.py b/json2xml/dicttoxml.py index cb529c93..b7a46347 100644 --- a/json2xml/dicttoxml.py +++ b/json2xml/dicttoxml.py @@ -5,7 +5,7 @@ import numbers from collections.abc import Callable, Sequence from random import SystemRandom -from typing import Any, Dict, Union +from typing import Any, Union from defusedxml.minidom import parseString @@ -505,10 +505,12 @@ def convert_kv( key: str, val: str | numbers.Number, attr_type: bool, - attr: dict[str, Any] = {}, + attr: dict[str, Any] | None = None, cdata: bool = False, ) -> str: """Converts a number or string into an XML element""" + if attr is None: + attr = {} key, attr = make_valid_xml_name(key, attr) if attr_type: @@ -518,9 +520,11 @@ def convert_kv( def convert_bool( - key: str, val: bool, attr_type: bool, attr: dict[str, Any] = {}, cdata: bool = False + key: str, val: bool, attr_type: bool, attr: dict[str, Any] | None = None, cdata: bool = False ) -> str: """Converts a boolean into an XML element""" + if attr is None: + attr = {} key, attr = make_valid_xml_name(key, attr) if attr_type: @@ -530,9 +534,11 @@ def convert_bool( def convert_none( - key: str, attr_type: bool, attr: dict[str, Any] = {}, cdata: bool = False + key: str, attr_type: bool, attr: dict[str, Any] | None = None, cdata: bool = False ) -> str: """Converts a null value into an XML element""" + if attr is None: + attr = {} key, attr = make_valid_xml_name(key, attr) if attr_type: @@ -669,6 +675,8 @@ def dicttoxml( 456 """ + if xml_namespaces is None: + xml_namespaces = {} output = [] namespace_str = "" for prefix in xml_namespaces: diff --git a/json2xml/json2xml.py b/json2xml/json2xml.py index db101b73..2d999b49 100644 --- a/json2xml/json2xml.py +++ b/json2xml/json2xml.py @@ -1,5 +1,5 @@ from pyexpat import ExpatError -from typing import Any, Dict, Optional +from typing import Any from defusedxml.minidom import parseString diff --git a/json2xml/utils.py b/json2xml/utils.py index bbcf43e1..85954a4a 100644 --- a/json2xml/utils.py +++ b/json2xml/utils.py @@ -1,6 +1,5 @@ """Utility methods for converting XML data to dictionary from various sources.""" import json -from typing import Dict, Optional import urllib3