Skip to content

Commit

Permalink
Redundant copy of AsyncIteratorWithoutAclose class
Browse files Browse the repository at this point in the history
  • Loading branch information
mikenerone committed Mar 16, 2024
1 parent a3683e1 commit ca05d55
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 17 deletions.
16 changes: 1 addition & 15 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytest
import trio

from slurry._utils import safe_aclose
from .fixtures import AsyncIteratorWithoutAclose

def fixture_gen_with_and_without_aclose(async_gen):

Expand Down Expand Up @@ -73,17 +73,3 @@ async def produce_mappings(interval):
vehicle['number'] = i
yield vehicle
await trio.sleep(interval)

class AsyncIteratorWithoutAclose:
def __init__(self, source_aiterable):
self.source_aiter = source_aiterable.__aiter__()

def __aiter__(self):
return self

async def __anext__(self):
try:
return await self.source_aiter.__anext__()
except StopAsyncIteration:
await safe_aclose(self.source_aiter)
raise
4 changes: 2 additions & 2 deletions tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import Any, Callable, Iterable

from slurry.environments import ThreadSection, ProcessSection
from slurry._utils import safe_aclose

class SyncSquares(ThreadSection):
def __init__(self, raise_after=math.inf) -> None:
Expand Down Expand Up @@ -54,6 +55,5 @@ async def __anext__(self):
try:
return await self.source_aiter.__anext__()
except StopAsyncIteration:
if hasattr(self.source_aiter, "aclose"):
await self.source_aiter.aclose()
await safe_aclose(self.source_aiter)
raise

0 comments on commit ca05d55

Please sign in to comment.