diff --git a/pymongo/asynchronous/helpers.py b/pymongo/asynchronous/helpers.py index 2b7420bbc..7ec1c18c5 100644 --- a/pymongo/asynchronous/helpers.py +++ b/pymongo/asynchronous/helpers.py @@ -313,9 +313,10 @@ def _handle_reauth(func: F) -> F: 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__() diff --git a/pymongo/asynchronous/mongo_client.py b/pymongo/asynchronous/mongo_client.py index 75e151d95..c743c569d 100644 --- a/pymongo/asynchronous/mongo_client.py +++ b/pymongo/asynchronous/mongo_client.py @@ -112,7 +112,6 @@ from pymongo.server_type import SERVER_TYPE from pymongo.write_concern import DEFAULT_WRITE_CONCERN, WriteConcern if TYPE_CHECKING: - import sys from types import TracebackType from bson.objectid import ObjectId @@ -126,11 +125,6 @@ if TYPE_CHECKING: 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") diff --git a/pymongo/asynchronous/pool.py b/pymongo/asynchronous/pool.py index 3cd7485a9..7c65af750 100644 --- a/pymongo/asynchronous/pool.py +++ b/pymongo/asynchronous/pool.py @@ -194,14 +194,9 @@ else: _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(), diff --git a/pymongo/synchronous/helpers.py b/pymongo/synchronous/helpers.py index 892d6a93e..3f0df2a3c 100644 --- a/pymongo/synchronous/helpers.py +++ b/pymongo/synchronous/helpers.py @@ -313,9 +313,10 @@ def _handle_reauth(func: F) -> F: 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__() diff --git a/pymongo/synchronous/mongo_client.py b/pymongo/synchronous/mongo_client.py index ddc9ae9a2..31b9cbc5f 100644 --- a/pymongo/synchronous/mongo_client.py +++ b/pymongo/synchronous/mongo_client.py @@ -111,7 +111,6 @@ from pymongo.synchronous.uri_parser import ( from pymongo.write_concern import DEFAULT_WRITE_CONCERN, WriteConcern if TYPE_CHECKING: - import sys from types import TracebackType from bson.objectid import ObjectId @@ -125,11 +124,6 @@ if TYPE_CHECKING: 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") diff --git a/pymongo/synchronous/pool.py b/pymongo/synchronous/pool.py index b71cec220..2026ba066 100644 --- a/pymongo/synchronous/pool.py +++ b/pymongo/synchronous/pool.py @@ -194,14 +194,9 @@ else: _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(), diff --git a/test/unified_format.py b/test/unified_format.py index fe1419c0d..0c200a15a 100644 --- a/test/unified_format.py +++ b/test/unified_format.py @@ -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