From 8db36ed6a537fb2efaf6e5da07102ec0065c498c Mon Sep 17 00:00:00 2001 From: Stephen Brown II Date: Wed, 24 Jul 2019 10:28:16 -0500 Subject: [PATCH] Allow string comparison for URL().__eq__ (#139) --- httpx/models.py | 2 +- tests/models/test_url.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/httpx/models.py b/httpx/models.py index 710c0303..9cbdc250 100644 --- a/httpx/models.py +++ b/httpx/models.py @@ -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() diff --git a/tests/models/test_url.py b/tests/models/test_url.py index 5f5208ca..70089e0f 100644 --- a/tests/models/test_url.py +++ b/tests/models/test_url.py @@ -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" -- 2.47.3