# Buggy code
def init_pool_manager(
    self,
    proxy: typing.Optional[Proxy],
    ssl_context: ssl.SSLContext,
    num_pools: int,
    maxsize: int,
    block: bool,
) -> typing.Union[urllib3.PoolManager, urllib3.ProxyManager]:
    if proxy is None:
        return urllib3.PoolManager(
            ssl_context=ssl_context,
            num_pools=num_pools,
            maxsize=maxsize,
            block=block,
        )
    else:
        return urllib3.ProxyManager(
            proxy_url=proxy.url,
            proxy_headers=dict(proxy.headers),
            ssl_context=ssl_context,
            num_pools=num_pools,
            maxsize=maxsize,
            block=block,
        )


# Traceback (TypeError)
$ ipython3 -c 'import httpx; r = httpx.get("https://www.google.com")'
parse_url http://127.0.0.1:1234 <class 'httpx.models.URL'>
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-1-d6fe3101235f> in <module>
----> 1 import httpx; r = httpx.get("https://www.google.com")

/usr/local/lib/python3.7/site-packages/httpx/api.py in get(url, params, headers, cookies, auth, allow_redirects, cert, verify, timeout, trust_env)
168         verify=verify,
169         timeout=timeout,
--> 170         trust_env=trust_env,
171     )
172

/usr/local/lib/python3.7/site-packages/httpx/api.py in request(method, url, params, data, files, json, headers, cookies, auth, timeout, allow_redirects, verify, cert, trust_env)
82     """
83     with Client(
---> 84         cert=cert, verify=verify, timeout=timeout, trust_env=trust_env,
85     ) as client:
86         return client.request(

/usr/local/lib/python3.7/site-packages/httpx/client.py in __init__(self, auth, params, headers, cookies, verify, cert, proxies, timeout, pool_limits, max_redirects, base_url, dispatch, app, trust_env)
477                 trust_env=trust_env,
478             )
--> 479             for key, proxy in proxy_map.items()
480         }
481

/usr/local/lib/python3.7/site-packages/httpx/client.py in <dictcomp>(.0)
477                 trust_env=trust_env,
478             )
--> 479             for key, proxy in proxy_map.items()
480         }
481

/usr/local/lib/python3.7/site-packages/httpx/client.py in init_proxy_dispatch(self, proxy, verify, cert, pool_limits, trust_env)
512             cert=cert,
513             pool_limits=pool_limits,
--> 514             trust_env=trust_env,
515         )
516

/usr/local/lib/python3.7/site-packages/httpx/dispatch/urllib3.py in __init__(self, proxy, verify, cert, trust_env, pool_limits)
58             num_pools=num_pools,
59             maxsize=maxsize,
---> 60             block=block,
61         )
62

/usr/local/lib/python3.7/site-packages/httpx/dispatch/urllib3.py in init_pool_manager(self, proxy, ssl_context, num_pools, maxsize, block)
83                 num_pools=num_pools,
84                 maxsize=maxsize,
---> 85                 block=block,
86             )
87

/usr/local/lib/python3.7/site-packages/urllib3/poolmanager.py in __init__(self, proxy_url, num_pools, headers, proxy_headers, **connection_pool_kw)
412                 proxy_url.port,
413             )
--> 414         proxy = parse_url(proxy_url)
415         if not proxy.port:
416             port = port_by_scheme.get(proxy.scheme, 80)

/usr/local/lib/python3.7/site-packages/urllib3/util/url.py in parse_url(url)
361     print('parse_url', url, type(url))
362     source_url = url
--> 363     if not SCHEME_RE.search(url):
364         url = "//" + url
365

TypeError: expected string or bytes-like object

# Fixed code
def init_pool_manager(
    self,
    proxy: typing.Optional[Proxy],
    ssl_context: ssl.SSLContext,
    num_pools: int,
    maxsize: int,
    block: bool,
) -> typing.Union[urllib3.PoolManager, urllib3.ProxyManager]:
    if proxy is None:
        return urllib3.PoolManager(
            ssl_context=ssl_context,
            num_pools=num_pools,
            maxsize=maxsize,
            block=block,
        )
    else:
        return urllib3.ProxyManager(
            proxy_url=str(proxy.url),
            proxy_headers=dict(proxy.headers),
            ssl_context=ssl_context,
            num_pools=num_pools,
            maxsize=maxsize,
            block=block,
        )