8000 Fix for comaparison of AnyUrl objects (#11082) · pydantic/pydantic@6fa92d1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6fa92d1

Browse files
Fix for comaparison of AnyUrl objects (#11082)
1 parent cc01258 commit 6fa92d1

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

pydantic/networks.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,18 @@ def __deepcopy__(self, memo: dict) -> Self:
224224
def __eq__(self, other: Any) -> bool:
225225
return self.__class__ is other.__class__ and self._url == other._url
226226

227+
def __lt__(self, other: Any) -> bool:
228+
return self.__class__ is other.__class__ and self._url < other._url
229+
230+
def __gt__(self, other: Any) -> bool:
231+
return self.__class__ is other.__class__ and self._url > other._url
232+
233+
def __le__(self, other: Any) -> bool:
234+
return self.__class__ is other.__class__ and self._url <= other._url
235+
236+
def __ge__(self, other: Any) -> bool:
237+
return self.__class__ is other.__class__ and self._url >= other._url
238+
227239
def __hash__(self) -> int:
228240
return hash(self._url)
229241

tests/test_networks.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,3 +1144,13 @@ def test_json_schema() -> None:
11441144

11451145
ser_json_schema = ta.json_schema(mode='serialization')
11461146
assert ser_json_schema == {'type': 'string', 'format': 'uri', 'minLength': 1, 'maxLength': 2083}
1147+
1148+
1149+
def test_any_url_comparison() -> None:
1150+
first_url = AnyUrl('https://a.com')
1151+
second_url = AnyUrl('https://b.com')
1152+
1153+
assert first_url < second_url
1154+
assert second_url > first_url
1155+
assert first_url <= second_url
1156+
assert second_url >= first_url

0 commit comments

Comments
 (0)
0