Allow string comparison for URL().__eq__ (#139)

This commit is contained in:
Stephen Brown II 2019-07-24 10:28:16 -05:00 committed by Tom Christie
parent 37df46a83b
commit 8db36ed6a5
2 changed files with 7 additions and 1 deletions

View 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()

View 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"