8000 Fix for comparison of AnyUrl objects by alexprabhat99 · Pull Request #11082 · pydantic/pydantic · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
comparsion for AnyUrl objects
  • Loading branch information
alexprabhat99 committed Dec 11, 2024
commit 1f63030988c882da4edf8a77169851e83a60fed7
11 changes: 10 additions & 1 deletion pydantic/networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,16 @@ def __eq__(self, other: Any) -> bool:
return self.__class__ is other.__class__ and self._url == other._url

def __lt__(self, other: Any) -> bool:
return self.__class__ is other.__class__ and str(self._url) < str(other._url)
return self.__class__ is other.__class__ and self._url < other._url

def __gt__(self, other: Any) -> bool:
return self.__class__ is other.__class__ and self._url > other._url

def __le__(self, other: Any) -> bool:
return self.__class__ is other.__class__ and self._url <= other._url

def __ge__(self, other: Any) -> bool:
return self.__class__ is other.__class__ and self._url >= other._url

def __hash__(self) -> int:
return hash(self._url)
Expand Down
13 changes: 9 additions & 4 deletions tests/test_networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,12 @@ def test_json_schema() -> None:
ser_json_schema = ta.json_schema(mode='serialization')
assert ser_json_schema == {'type': 'string', 'format': 'uri', 'minLength': 1, 'maxLength': 2083}

def test_any_url_comparison() -> None:
first_url = AnyUrl('https://a.com')
second_url = AnyUrl('https://b.com')
assert second_url > first_url

def test_any_url_comparison() -> None:
first_url = AnyUrl('https://a.com')
second_url = AnyUrl('https://b.com')

assert first_url < second_url
assert second_url > first_url
assert first_url <= second_url
assert second_url >= first_url
Loading
0