Skip to content

Commit

Permalink
fixes after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
graingert committed Jan 7, 2025
1 parent 0203d03 commit 6fba791
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/anyio/_core/_sockets.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ async def try_connect(remote_host: str, event: Event) -> None:
)
raise OSError("All connection attempts failed") from cause
finally:
del oserrors
oserrors = []

if tls or tls_hostname or ssl_context:
try:
Expand Down
29 changes: 23 additions & 6 deletions tests/test_sockets.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
create_unix_datagram_socket,
create_unix_listener,
fail_after,
get_current_task,
getaddrinfo,
getnameinfo,
move_on_after,
Expand All @@ -59,6 +60,7 @@
SocketAttribute,
SocketListener,
SocketStream,
TaskStatus,
)
from anyio.lowlevel import checkpoint
from anyio.streams.stapled import MultiListener
Expand Down Expand Up @@ -134,14 +136,29 @@ def check_asyncio_bug(anyio_backend_name: str, family: AnyIPAddressFamily) -> No
pytest.skip("Does not work due to a known bug (39148)")


if sys.version_info <= (3, 11):
if sys.version_info >= (3, 14):

def no_other_refs() -> list[object]:
return [sys._getframe(1)]
else:
async def no_other_refs() -> list[object]:
frame = sys._getframe(1)
coro = get_current_task().coro

async def get_coro_for_frame(*, task_status: TaskStatus[object]) -> None:
my_coro = coro
while my_coro.cr_frame is not frame:
my_coro = my_coro.cr_await
task_status.started(my_coro)

async with create_task_group() as tg:
return [await tg.start(get_coro_for_frame)]

def no_other_refs() -> list[object]:
elif sys.version_info >= (3, 11):

async def no_other_refs() -> list[object]:
return []
else:

async def no_other_refs() -> list[object]:
return [sys._getframe(1)]


_T = TypeVar("_T")
Expand Down Expand Up @@ -347,7 +364,7 @@ async def test_happy_eyeballs_refcycles(self) -> None:
exc = e.__cause__

assert isinstance(exc, OSError)
assert gc.get_referrers(exc) == no_other_refs()
assert gc.get_referrers(exc) == await no_other_refs()

@pytest.mark.parametrize(
"target, exception_class",
Expand Down

0 comments on commit 6fba791

Please sign in to comment.