quandyfactory/dicttoxml

collections.Iterable is deprecated

VityasZV opened this issue · 2 comments

Hello! Here is and example of attempt to convert dict with iterable val, so an exception occured.
Could be easily fixed by replacing collections.Iterable with collections.abc.Iterable


obj = {'domains': [{'domain': 'test.bike'}]}, ids = False, parent = 'request'
attr_type = False, item_func = <function default_item_func at 0xffff997cc4c0>
cdata = False

    def convert_dict(obj, ids, parent, attr_type, item_func, cdata):
        """Converts a dict into an XML string."""
        LOG.info('Inside convert_dict(): obj type is: "%s", obj="%s"' % (
            type(obj).__name__, unicode_me(obj))
        )
        output = []
        addline = output.append
    
        item_name = item_func(parent)
    
        for key, val in obj.items():
            LOG.info('Looping inside convert_dict(): key="%s", val="%s", type(val)="%s"' % (
                unicode_me(key), unicode_me(val), type(val).__name__)
            )
    
            attr = {} if not ids else {'id': '%s' % (get_unique_id(parent)) }
    
            key, attr = make_valid_xml_name(key, attr)
    
            if isinstance(val, numbers.Number) or type(val) in (str, unicode):
                addline(convert_kv(key, val, attr_type, attr, cdata))
    
            elif hasattr(val, 'isoformat'): # datetime
                addline(convert_kv(key, val.isoformat(), attr_type, attr, cdata))
    
            elif type(val) == bool:
                addline(convert_bool(key, val, attr_type, attr, cdata))
    
            elif isinstance(val, dict):
                if attr_type:
                    attr['type'] = get_xml_type(val)
                addline('<%s%s>%s</%s>' % (
                    key, make_attrstring(attr),
                    convert_dict(val, ids, key, attr_type, item_func, cdata),
                    key
                    )
                )
    
>           elif isinstance(val, collections.Iterable):
E           AttributeError: module 'collections' has no attribute 'Iterable'

/usr/local/lib/python3.10/site-packages/dicttoxml.py:235: AttributeError

Any suggested workarounds for this? It's currently breaking one of my scripts

Edit: It looks like this is actually fixed in the most recent version of the repo, just not reflected in the package manager

thanks for the info!!!