Cleanup sys.version_info compat code (#1698)
This commit is contained in:
parent
8fbf84d314
commit
1d9adfa3b9
@ -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__()
|
||||
|
||||
@ -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")
|
||||
|
||||
|
||||
@ -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(),
|
||||
|
||||
@ -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__()
|
||||
|
||||
@ -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")
|
||||
|
||||
|
||||
@ -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(),
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user