* Added test for expected URL class behavior
* Updated URL class, tests pass
* Updated to include type in error message
# We don't want to normalize relative URLs, since doing so
# removes any leading `../` portion.
self._uri_reference = self._uri_reference.normalize()
- else:
+ elif isinstance(url, URL):
self._uri_reference = url._uri_reference
+ else:
+ raise TypeError(
+ f"Invalid type for url. Expected str or httpx.URL, got {type(url)}"
+ )
# Add any query parameters, merging with any in the URL if needed.
if params:
def test_url_invalid():
with pytest.raises(httpx.InvalidURL):
httpx.URL("https://😇/")
+
+
+def test_url_invalid_type():
+ class ExternalURLClass: # representing external URL class
+ pass
+
+ with pytest.raises(TypeError):
+ httpx.URL(ExternalURLClass()) # type: ignore