Build url urlunsplit style, but optionally handle path as a list and/or query as a dict

def parts_to_url(parts=None, scheme=None, netloc=None, path=None, query=None, fragment=None):
    """ Build url urlunsplit style, but optionally handle path as a list and/or query as a dict """

    if isinstance(parts, _urllib_parse.SplitResult):
        scheme, netloc, path, query, fragment = parts
    elif parts and isinstance(parts, dict):
        scheme = parts.get('scheme', 'http')
        netloc = parts.get('netloc', '')
        path = parts.get('path', [])
        query = parts.get('query', {})
        fragment = parts.get('fragment', '')

    if isinstance(path, (list, tuple)):
        path = '/' + '/'.join(path).strip('/')
    if isinstance(query, (dict, tuple)):
        query = _unquote(_urlencode(query, doseq=True))

    return _urlunsplit((scheme, netloc, path, query, fragment)) or None