Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup sys.version_info compat code #1698

Merged
merged 2 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
9 changes: 2 additions & 7 deletions pymongo/asynchronous/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,9 @@ def _set_keepalive_times(sock: socket.socket) -> None:
_METADATA: dict[str, Any] = {"driver": {"name": "PyMongo", "version": __version__}}

if sys.platform.startswith("linux"):
# platform.linux_distribution was deprecated in Python 3.5
# and removed in Python 3.8. Starting in Python 3.5 it
# raises DeprecationWarning
# DeprecationWarning: dist() and linux_distribution() functions are deprecated in Python 3.5
_name = platform.system()
_METADATA["os"] = {
"type": _name,
"name": _name,
"type": platform.system(),
"name": platform.system(),
"architecture": platform.machine(),
# Kernel version (e.g. 4.4.0-17-generic).
"version": platform.release(),
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
9 changes: 2 additions & 7 deletions pymongo/synchronous/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,9 @@ def _set_keepalive_times(sock: socket.socket) -> None:
_METADATA: dict[str, Any] = {"driver": {"name": "PyMongo", "version": __version__}}

if sys.platform.startswith("linux"):
# platform.linux_distribution was deprecated in Python 3.5
# and removed in Python 3.8. Starting in Python 3.5 it
# raises DeprecationWarning
# DeprecationWarning: dist() and linux_distribution() functions are deprecated in Python 3.5
_name = platform.system()
_METADATA["os"] = {
"type": _name,
"name": _name,
"type": platform.system(),
"name": platform.system(),
"architecture": platform.machine(),
# Kernel version (e.g. 4.4.0-17-generic).
"version": platform.release(),
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
Loading