Skip to content

Commit 1d9adfa

Browse files
authored
Cleanup sys.version_info compat code (mongodb#1698)
1 parent 8fbf84d commit 1d9adfa

File tree

7 files changed

+20
-44
lines changed

7 files changed

+20
-44
lines changed

pymongo/asynchronous/helpers.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,10 @@ async def inner(*args: Any, **kwargs: Any) -> Any:
313313
return cast(F, inner)
314314

315315

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

pymongo/asynchronous/mongo_client.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@
112112
from pymongo.write_concern import DEFAULT_WRITE_CONCERN, WriteConcern
113113

114114
if TYPE_CHECKING:
115-
import sys
116115
from types import TracebackType
117116

118117
from bson.objectid import ObjectId
@@ -126,11 +125,6 @@
126125
from pymongo.asynchronous.server_selectors import Selection
127126
from pymongo.read_concern import ReadConcern
128127

129-
if sys.version_info[:2] >= (3, 9):
130-
pass
131-
else:
132-
# Deprecated since version 3.9: collections.abc.Generator now supports [].
133-
pass
134128

135129
T = TypeVar("T")
136130

pymongo/asynchronous/pool.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,9 @@ def _set_keepalive_times(sock: socket.socket) -> None:
194194
_METADATA: dict[str, Any] = {"driver": {"name": "PyMongo", "version": __version__}}
195195

196196
if sys.platform.startswith("linux"):
197-
# platform.linux_distribution was deprecated in Python 3.5
198-
# and removed in Python 3.8. Starting in Python 3.5 it
199-
# raises DeprecationWarning
200-
# DeprecationWarning: dist() and linux_distribution() functions are deprecated in Python 3.5
201-
_name = platform.system()
202197
_METADATA["os"] = {
203-
"type": _name,
204-
"name": _name,
198+
"type": platform.system(),
199+
"name": platform.system(),
205200
"architecture": platform.machine(),
206201
# Kernel version (e.g. 4.4.0-17-generic).
207202
"version": platform.release(),

pymongo/synchronous/helpers.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,10 @@ def inner(*args: Any, **kwargs: Any) -> Any:
313313
return cast(F, inner)
314314

315315

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

pymongo/synchronous/mongo_client.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@
111111
from pymongo.write_concern import DEFAULT_WRITE_CONCERN, WriteConcern
112112

113113
if TYPE_CHECKING:
114-
import sys
115114
from types import TracebackType
116115

117116
from bson.objectid import ObjectId
@@ -125,11 +124,6 @@
125124
from pymongo.synchronous.server import Server
126125
from pymongo.synchronous.server_selectors import Selection
127126

128-
if sys.version_info[:2] >= (3, 9):
129-
pass
130-
else:
131-
# Deprecated since version 3.9: collections.abc.Generator now supports [].
132-
pass
133127

134128
T = TypeVar("T")
135129

pymongo/synchronous/pool.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,9 @@ def _set_keepalive_times(sock: socket.socket) -> None:
194194
_METADATA: dict[str, Any] = {"driver": {"name": "PyMongo", "version": __version__}}
195195

196196
if sys.platform.startswith("linux"):
197-
# platform.linux_distribution was deprecated in Python 3.5
198-
# and removed in Python 3.8. Starting in Python 3.5 it
199-
# raises DeprecationWarning
200-
# DeprecationWarning: dist() and linux_distribution() functions are deprecated in Python 3.5
201-
_name = platform.system()
202197
_METADATA["os"] = {
203-
"type": _name,
204-
"name": _name,
198+
"type": platform.system(),
199+
"name": platform.system(),
205200
"architecture": platform.machine(),
206201
# Kernel version (e.g. 4.4.0-17-generic).
207202
"version": platform.release(),

test/unified_format.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -195,14 +195,10 @@ def with_metaclass(meta, *bases):
195195
# the actual metaclass.
196196
class metaclass(type):
197197
def __new__(cls, name, this_bases, d):
198-
if sys.version_info[:2] >= (3, 7): # noqa: UP036
199-
# This version introduced PEP 560 that requires a bit
200-
# of extra care (we mimic what is done by __build_class__).
201-
resolved_bases = types.resolve_bases(bases)
202-
if resolved_bases is not bases:
203-
d["__orig_bases__"] = bases
204-
else:
205-
resolved_bases = bases
198+
# __orig_bases__ is required by PEP 560.
199+
resolved_bases = types.resolve_bases(bases)
200+
if resolved_bases is not bases:
201+
d["__orig_bases__"] = bases
206202
return meta(name, resolved_bases, d)
207203

208204
@classmethod

0 commit comments

Comments
 (0)