Skip to content

Commit 9faa8d9

Browse files
alexprabhat99sydney-runkle
authored andcommitted
Fix for comaparison of AnyUrl objects (#11082)
1 parent 6fd6a03 commit 9faa8d9

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
@@ -1147,6 +1147,16 @@ def test_json_schema() -> None:
11471147
assert ser_json_schema == {'type': 'string', 'format': 'uri', 'minLength': 1, 'maxLength': 2083}
11481148

11491149

1150+
def test_any_url_comparison() -> None:
1151+
first_url = AnyUrl('https://a.com')
1152+
second_url = AnyUrl('https://b.com')
1153+
1154+
assert first_url < second_url
1155+
assert second_url > first_url
1156+
assert first_url <= second_url
1157+
assert second_url >= first_url
1158+
1159+
11501160
def test_max_length_base_url() -> None:
11511161
class Model(BaseModel):
11521162
url: AnyUrl = Field(max_length=20)

0 commit comments

Comments
 (0)