Skip to content

Commit

Permalink
Cleanup sys.version_info compat code
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaneHarvey committed Jun 24, 2024
1 parent 77087dd commit 7e07cae
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 30 deletions.
11 changes: 6 additions & 5 deletions pymongo/asynchronous/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,10 @@ async def inner(*args: Any, **kwargs: Any) -> Any:
return cast(F, inner)


async def anext(cls: Any) -> Any:
"""Compatibility function until we drop 3.9 support: https://docs.python.org/3/library/functions.html#anext."""
if sys.version_info >= (3, 10):
return await builtins.anext(cls)
else:
if sys.version_info >= (3, 10):
anext = builtins.anext
else:

async def anext(cls: Any) -> Any:
"""Compatibility function until we drop 3.9 support: https://docs.python.org/3/library/functions.html#anext."""
return await cls.__anext__()
6 changes: 0 additions & 6 deletions pymongo/asynchronous/mongo_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@
from pymongo.write_concern import DEFAULT_WRITE_CONCERN, WriteConcern

if TYPE_CHECKING:
import sys
from types import TracebackType

from bson.objectid import ObjectId
Expand All @@ -126,11 +125,6 @@
from pymongo.asynchronous.server_selectors import Selection
from pymongo.read_concern import ReadConcern

if sys.version_info[:2] >= (3, 9):
pass
else:
# Deprecated since version 3.9: collections.abc.Generator now supports [].
pass

T = TypeVar("T")

Expand Down
11 changes: 6 additions & 5 deletions pymongo/synchronous/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,10 @@ def inner(*args: Any, **kwargs: Any) -> Any:
return cast(F, inner)


def next(cls: Any) -> Any:
"""Compatibility function until we drop 3.9 support: https://docs.python.org/3/library/functions.html#anext."""
if sys.version_info >= (3, 10):
return builtins.next(cls)
else:
if sys.version_info >= (3, 10):
next = builtins.next
else:

def next(cls: Any) -> Any:
"""Compatibility function until we drop 3.9 support: https://docs.python.org/3/library/functions.html#anext."""
return cls.__next__()
6 changes: 0 additions & 6 deletions pymongo/synchronous/mongo_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@
from pymongo.write_concern import DEFAULT_WRITE_CONCERN, WriteConcern

if TYPE_CHECKING:
import sys
from types import TracebackType

from bson.objectid import ObjectId
Expand All @@ -125,11 +124,6 @@
from pymongo.synchronous.server import Server
from pymongo.synchronous.server_selectors import Selection

if sys.version_info[:2] >= (3, 9):
pass
else:
# Deprecated since version 3.9: collections.abc.Generator now supports [].
pass

T = TypeVar("T")

Expand Down
12 changes: 4 additions & 8 deletions test/unified_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,10 @@ def with_metaclass(meta, *bases):
# the actual metaclass.
class metaclass(type):
def __new__(cls, name, this_bases, d):
if sys.version_info[:2] >= (3, 7): # noqa: UP036
# This version introduced PEP 560 that requires a bit
# of extra care (we mimic what is done by __build_class__).
resolved_bases = types.resolve_bases(bases)
if resolved_bases is not bases:
d["__orig_bases__"] = bases
else:
resolved_bases = bases
# __orig_bases__ is required by PEP 560.
resolved_bases = types.resolve_bases(bases)
if resolved_bases is not bases:
d["__orig_bases__"] = bases
return meta(name, resolved_bases, d)

@classmethod
Expand Down

0 comments on commit 7e07cae

Please sign in to comment.