]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Allow string comparison for URL().__eq__ (#139)
authorStephen Brown II <stephen.brownii@rackspace.com>
Wed, 24 Jul 2019 15:28:16 +0000 (10:28 -0500)
committerTom Christie <tom@tomchristie.com>
Wed, 24 Jul 2019 15:28:16 +0000 (16:28 +0100)
httpx/models.py
tests/models/test_url.py

index 710c0303df4eb8d55b23a2553ecd4db34862261e..9cbdc250e22f4551a1e6b02166794061751e3793 100644 (file)
@@ -204,7 +204,7 @@ class URL:
         return hash(str(self))
 
     def __eq__(self, other: typing.Any) -> bool:
-        return isinstance(other, URL) and str(self) == str(other)
+        return isinstance(other, (URL, str)) and str(self) == str(other)
 
     def __str__(self) -> str:
         return self.components.unsplit()
index 5f5208ca927b4eb1cd9c804d72668d10f5480c70..70089e0f1f00d518afaef43205e53e0a2b506f4d 100644 (file)
@@ -25,6 +25,12 @@ def test_url():
     assert new.scheme == "http"
 
 
+def test_url_eq_str():
+    url = URL("https://example.org:123/path/to/somewhere?abc=123#anchor")
+    assert url == "https://example.org:123/path/to/somewhere?abc=123#anchor"
+    assert str(url) == url
+
+
 def test_url__params():
     url = URL("https://example.org:123/path/to/somewhere", params={"a": "123"})
     assert str(url) == "https://example.org:123/path/to/somewhere?a=123"