Skip to content

Commit b42633b

Browse files
committed
restore py39 compat
1 parent 9d12568 commit b42633b

38 files changed

+70
-0
lines changed

gridfs/asynchronous/grid_file.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
from pymongo.asynchronous.collection import AsyncCollection
4747
from pymongo.asynchronous.cursor import AsyncCursor
4848
from pymongo.asynchronous.database import AsyncDatabase
49+
from pymongo.asynchronous.helpers import anext
4950
from pymongo.common import validate_string
5051
from pymongo.errors import (
5152
BulkWriteError,

gridfs/synchronous/grid_file.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
from pymongo.synchronous.collection import Collection
5858
from pymongo.synchronous.cursor import Cursor
5959
from pymongo.synchronous.database import Database
60+
from pymongo.synchronous.helpers import next
6061

6162
_IS_SYNC = True
6263

pymongo/asynchronous/cursor.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
from bson.code import Code
3838
from bson.son import SON
3939
from pymongo import _csot, helpers_shared
40+
from pymongo.asynchronous.helpers import anext
4041
from pymongo.collation import validate_collation_or_none
4142
from pymongo.common import (
4243
validate_is_document_type,

pymongo/asynchronous/helpers.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
from __future__ import annotations
1717

1818
import asyncio
19+
import builtins
1920
import socket
21+
import sys
2022
from typing import (
2123
Any,
2224
Callable,
@@ -84,3 +86,17 @@ async def _getaddrinfo(
8486
return await loop.getaddrinfo(host, port, **kwargs) # type: ignore[return-value]
8587
else:
8688
return socket.getaddrinfo(host, port, **kwargs)
89+
90+
91+
if sys.version_info >= (3, 10):
92+
anext = builtins.anext
93+
aiter = builtins.aiter
94+
else:
95+
96+
async def anext(cls: Any) -> Any:
97+
"""Compatibility function until we drop 3.9 support: https://docs.python.org/3/library/functions.html#anext."""
98+
return await cls.__anext__()
99+
100+
def aiter(cls: Any) -> Any:
101+
"""Compatibility function until we drop 3.9 support: https://docs.python.org/3/library/functions.html#anext."""
102+
return cls.__aiter__()

pymongo/synchronous/cursor.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
_RawBatchQuery,
5656
)
5757
from pymongo.response import PinnedResponse
58+
from pymongo.synchronous.helpers import next
5859
from pymongo.typings import _Address, _CollationIn, _DocumentOut, _DocumentType
5960
from pymongo.write_concern import validate_boolean
6061

pymongo/synchronous/helpers.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
from __future__ import annotations
1717

1818
import asyncio
19+
import builtins
1920
import socket
21+
import sys
2022
from typing import (
2123
Any,
2224
Callable,
@@ -84,3 +86,17 @@ def _getaddrinfo(
8486
return loop.getaddrinfo(host, port, **kwargs) # type: ignore[return-value]
8587
else:
8688
return socket.getaddrinfo(host, port, **kwargs)
89+
90+
91+
if sys.version_info >= (3, 10):
92+
next = builtins.next
93+
iter = builtins.iter
94+
else:
95+
96+
def next(cls: Any) -> Any:
97+
"""Compatibility function until we drop 3.9 support: https://docs.python.org/3/library/functions.html#next."""
98+
return cls.__next__()
99+
100+
def iter(cls: Any) -> Any:
101+
"""Compatibility function until we drop 3.9 support: https://docs.python.org/3/library/functions.html#next."""
102+
return cls.__iter__()

test/asynchronous/test_change_stream.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
from bson.raw_bson import DEFAULT_RAW_BSON_OPTIONS, RawBSONDocument
4949
from pymongo import AsyncMongoClient
5050
from pymongo.asynchronous.command_cursor import AsyncCommandCursor
51+
from pymongo.asynchronous.helpers import anext
5152
from pymongo.errors import (
5253
InvalidOperation,
5354
OperationFailure,

test/asynchronous/test_client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
from pymongo.asynchronous.command_cursor import AsyncCommandCursor
9393
from pymongo.asynchronous.cursor import AsyncCursor, CursorType
9494
from pymongo.asynchronous.database import AsyncDatabase
95+
from pymongo.asynchronous.helpers import anext
9596
from pymongo.asynchronous.mongo_client import AsyncMongoClient
9697
from pymongo.asynchronous.pool import (
9798
AsyncConnection,

test/asynchronous/test_collation.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from test.utils_shared import EventListener, OvertCommandListener
2222
from typing import Any
2323

24+
from pymongo.asynchronous.helpers import anext
2425
from pymongo.collation import (
2526
Collation,
2627
CollationAlternate,

test/asynchronous/test_collection.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from typing import Any, Iterable, no_type_check
2626

2727
from pymongo.asynchronous.database import AsyncDatabase
28+
from pymongo.asynchronous.helpers import anext
2829

2930
sys.path[0:0] = [""]
3031

0 commit comments

Comments
 (0)