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

Skip to content

Fix for comparison of AnyUrl objects #11082

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 12 additions & 0 deletions pydantic/networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,18 @@ def __deepcopy__(self, memo: dict) -> Self:
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 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
10 changes: 10 additions & 0 deletions tests/test_networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1144,3 +1144,13 @@ 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 first_url < second_url
assert second_url > first_url
assert first_url <= second_url
assert second_url >= first_url
Loading
0