From f6fd6908e9050d702936de244c65cce1c02b785c Mon Sep 17 00:00:00 2001 From: Vinit Kumar Date: Fri, 10 Sep 2021 22:54:30 +0530 Subject: [PATCH] Feat/cleanup and deprecation fix (#78) * :art: feat: run black on the dicttoxml * fix: issue with Deprecation with Python3.10 DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3, and in 3.10 it will stop working * :arrow_up: feat: use latest python3.10-rc2 --- .github/workflows/pythonpackage.yml | 2 +- json2xml/dicttoxml.py | 62 +++++++++++++++++++++++------ 2 files changed, 50 insertions(+), 14 deletions(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index b0395e1..16252fe 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -8,7 +8,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: [3.6, 3.7, 3.8, 3.9, pypy3, '3.10.0-rc.1'] + python-version: [3.6, 3.7, 3.8, 3.9, pypy3, '3.10.0-rc.2'] os: [ ubuntu-20.04, macOS-latest, diff --git a/json2xml/dicttoxml.py b/json2xml/dicttoxml.py index 229d69c..43b8e10 100755 --- a/json2xml/dicttoxml.py +++ b/json2xml/dicttoxml.py @@ -61,7 +61,7 @@ def get_xml_type(val): return "null" if isinstance(val, dict): return "dict" - if isinstance(val, collections.Iterable): + if isinstance(val, collections.abc.Iterable): return "list" return type(val).__name__ @@ -159,7 +159,7 @@ def convert(obj, ids, attr_type, item_func, cdata, item_wrap, parent="root"): if isinstance(obj, dict): return convert_dict(obj, ids, parent, attr_type, item_func, cdata, item_wrap) - if isinstance(obj, collections.Iterable): + if isinstance(obj, collections.abc.Iterable): return convert_list(obj, ids, parent, attr_type, item_func, cdata, item_wrap) raise TypeError("Unsupported data type: %s (%s)" % (obj, type(obj).__name__)) @@ -206,7 +206,7 @@ def convert_dict(obj, ids, parent, attr_type, item_func, cdata, item_wrap): ) ) - elif isinstance(val, collections.Iterable): + elif isinstance(val, collections.abc.Iterable): if attr_type: attr["type"] = get_xml_type(val) addline( @@ -258,12 +258,20 @@ def convert_list(items, ids, parent, attr_type, item_func, cdata, item_wrap): elif isinstance(item, dict): if not attr_type: - if (item_wrap): + if item_wrap: addline( "<%s>%s" % ( item_name, - convert_dict(item, ids, parent, attr_type, item_func, cdata, item_wrap), + convert_dict( + item, + ids, + parent, + attr_type, + item_func, + cdata, + item_wrap, + ), item_name, ) ) @@ -271,35 +279,61 @@ def convert_list(items, ids, parent, attr_type, item_func, cdata, item_wrap): addline( "%s" % ( - convert_dict(item, ids, parent, attr_type, item_func, cdata, item_wrap), + convert_dict( + item, + ids, + parent, + attr_type, + item_func, + cdata, + item_wrap, + ), ) ) else: - if (item_wrap): + if item_wrap: addline( '<%s type="dict">%s' % ( item_name, - convert_dict(item, ids, parent, attr_type, item_func, cdata, item_wrap), + convert_dict( + item, + ids, + parent, + attr_type, + item_func, + cdata, + item_wrap, + ), item_name, ) ) else: addline( - '%s' + "%s" % ( - convert_dict(item, ids, parent, attr_type, item_func, cdata, item_wrap), + convert_dict( + item, + ids, + parent, + attr_type, + item_func, + cdata, + item_wrap, + ), ) ) - elif isinstance(item, collections.Iterable): + elif isinstance(item, collections.abc.Iterable): if not attr_type: addline( "<%s %s>%s" % ( item_name, make_attrstring(attr), - convert_list(item, ids, item_name, attr_type, item_func, cdata, item_wrap), + convert_list( + item, ids, item_name, attr_type, item_func, cdata, item_wrap + ), item_name, ) ) @@ -309,7 +343,9 @@ def convert_list(items, ids, parent, attr_type, item_func, cdata, item_wrap): % ( item_name, make_attrstring(attr), - convert_list(item, ids, item_name, attr_type, item_func, cdata, item_wrap), + convert_list( + item, ids, item_name, attr_type, item_func, cdata, item_wrap + ), item_name, ) )