Skip to content

Commit c36d5d5

Browse files
committed
AsyncGridOut fixes
1 parent 397ea6b commit c36d5d5

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

gridfs/asynchronous/grid_file.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,7 +1400,10 @@ async def __aexit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> Any:
14001400
return False
14011401

14021402

1403-
class AsyncGridOut(io.IOBase):
1403+
GRIDOUT_BASE_CLASS = io.IOBase if _IS_SYNC else object
1404+
1405+
1406+
class AsyncGridOut(GRIDOUT_BASE_CLASS):
14041407
"""Class to read data out of GridFS."""
14051408

14061409
def __init__(
@@ -1486,13 +1489,13 @@ def __init__(
14861489
_file: Any
14871490
_chunk_iter: Any
14881491

1489-
async def __anext__(self) -> bytes:
1490-
return super().__next__()
1491-
1492-
# This is a duplicate definition of __next__ for the synchronous API
1493-
# due to the limitations of our synchro process
14941492
if not _IS_SYNC:
14951493

1494+
async def __anext__(self) -> bytes:
1495+
return await self.readline()
1496+
1497+
# This is a duplicate definition of __next__ for the synchronous API
1498+
# due to the limitations of our synchro process
14961499
def __next__(self) -> bytes: # noqa: F811, RUF100
14971500
raise TypeError(
14981501
"AsyncGridOut does not support synchronous iteration. Use `async for` instead"

gridfs/synchronous/grid_file.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,7 +1388,10 @@ def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> Any:
13881388
return False
13891389

13901390

1391-
class GridOut(io.IOBase):
1391+
GRIDOUT_BASE_CLASS = io.IOBase if _IS_SYNC else object
1392+
1393+
1394+
class GridOut(GRIDOUT_BASE_CLASS):
13921395
"""Class to read data out of GridFS."""
13931396

13941397
def __init__(
@@ -1474,13 +1477,13 @@ def __init__(
14741477
_file: Any
14751478
_chunk_iter: Any
14761479

1477-
def __next__(self) -> bytes:
1478-
return super().__next__()
1479-
1480-
# This is a duplicate definition of __next__ for the synchronous API
1481-
# due to the limitations of our synchro process
14821480
if not _IS_SYNC:
14831481

1482+
def __next__(self) -> bytes:
1483+
return self.readline()
1484+
1485+
# This is a duplicate definition of __next__ for the synchronous API
1486+
# due to the limitations of our synchro process
14841487
def __next__(self) -> bytes: # noqa: F811, RUF100
14851488
raise TypeError("GridOut does not support synchronous iteration. Use `for` instead")
14861489

0 commit comments

Comments
 (0)