Skip to content

Commit 80ef547

Browse files
committed
Remove default for anext
1 parent 63d6dd5 commit 80ef547

File tree

4 files changed

+12
-16
lines changed

4 files changed

+12
-16
lines changed

pymongo/asynchronous/helpers.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,9 @@ async def inner(*args: Any, **kwargs: Any) -> Any:
7373
aiter = builtins.aiter
7474
else:
7575

76-
async def anext(cls: Any, default: Any) -> Any:
76+
async def anext(cls: Any) -> Any:
7777
"""Compatibility function until we drop 3.9 support: https://docs.python.org/3/library/functions.html#anext."""
78-
try:
79-
return await cls.__anext__()
80-
except StopAsyncIteration:
81-
if default:
82-
return default
83-
raise
78+
return await cls.__anext__()
8479

8580
def aiter(cls: Any) -> Any:
8681
"""Compatibility function until we drop 3.9 support: https://docs.python.org/3/library/functions.html#anext."""

pymongo/synchronous/helpers.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,9 @@ def inner(*args: Any, **kwargs: Any) -> Any:
7373
iter = builtins.iter
7474
else:
7575

76-
def next(cls: Any, default: Any) -> Any:
76+
def next(cls: Any) -> Any:
7777
"""Compatibility function until we drop 3.9 support: https://docs.python.org/3/library/functions.html#next."""
78-
try:
79-
return cls.__next__()
80-
except StopIteration:
81-
if default:
82-
return default
83-
raise
78+
return cls.__next__()
8479

8580
def iter(cls: Any) -> Any:
8681
"""Compatibility function until we drop 3.9 support: https://docs.python.org/3/library/functions.html#next."""

test/asynchronous/unified_format.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,10 @@ def __init__(self, find_cursor, client):
179179
@classmethod
180180
async def create(cls, find_cursor, client):
181181
cursor = cls(find_cursor, client)
182-
cursor.first_result = await anext(cursor.find_cursor, None)
182+
try:
183+
cursor.first_result = await anext(cursor.find_cursor)
184+
except StopAsyncIteration:
185+
cursor.first_result = None
183186
return cursor
184187

185188
@property

test/unified_format.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,10 @@ def __init__(self, find_cursor, client):
179179
@classmethod
180180
def create(cls, find_cursor, client):
181181
cursor = cls(find_cursor, client)
182-
cursor.first_result = next(cursor.find_cursor, None)
182+
try:
183+
cursor.first_result = next(cursor.find_cursor)
184+
except StopIteration:
185+
cursor.first_result = None
183186
return cursor
184187

185188
@property

0 commit comments

Comments
 (0)