Skip to content
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

feat: make interleave with pop_addr_infos_interleave optional to match cpython #28

Merged
merged 2 commits into from
Dec 11, 2023
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
6 changes: 5 additions & 1 deletion src/aiohappyeyeballs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,18 @@ def addr_to_addr_infos(
return [(family, socket.SOCK_STREAM, socket.IPPROTO_TCP, "", addr)]


def pop_addr_infos_interleave(addr_infos: List[AddrInfoType], interleave: int) -> None:
def pop_addr_infos_interleave(
addr_infos: List[AddrInfoType], interleave: Optional[int] = None
) -> None:
"""
Pop addr_info from the list of addr_infos by family up to interleave times.

The interleave parameter is used to know how many addr_infos for
each family should be popped of the top of the list.
"""
seen: Dict[int, int] = {}
if interleave is None:
interleave = 1
to_remove: List[AddrInfoType] = []
for addr_info in addr_infos:
family = addr_info[0]
Expand Down
3 changes: 3 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ def test_pop_addr_infos_interleave():
addr_info_copy = addr_info.copy()
pop_addr_infos_interleave(addr_info_copy, 2)
assert addr_info_copy == []
addr_info_copy = addr_info.copy()
pop_addr_infos_interleave(addr_info_copy)
assert addr_info_copy == [ipv6_addr_info_2]


def test_remove_addr_infos():
Expand Down
Loading