Skip to content
Myr

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

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Stephen Brown II · committed by Tom Christie · parent 37df46a · Browse files · 2 files+7 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+7 added−1 removed

  • tests:+6 added−0 removed
  • other:+1 added−1 removed

2 files+7 added−1 removed

modified:httpx/models.py+1 added-1 removed
202 unmodified lines
203 def __hash__(self) -> int:204 return hash(str(self))205206 def __eq__(self, other: typing.Any) -> bool:207 return isinstance(other, URL) and str(self) == str(other)207 return isinstance(other, (URL, str)) and str(self) == str(other)208209 def __str__(self) -> str:210 return self.components.unsplit()211
957 unmodified lines
modified:tests/models/test_url.py+6 added
23 unmodified lines
24 assert new == URL("http://example.org:123/path/to/somewhere?abc=123#anchor")25 assert new.scheme == "http"262728def test_url_eq_str():29 url = URL("https://example.org:123/path/to/somewhere?abc=123#anchor")30 assert url == "https://example.org:123/path/to/somewhere?abc=123#anchor"31 assert str(url) == url323334def test_url__params():35 url = URL("https://example.org:123/path/to/somewhere", params={"a": "123"})36 assert str(url) == "https://example.org:123/path/to/somewhere?a=123"37
13 unmodified lines