Skip to content
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
24 changes: 12 additions & 12 deletions .evergreen/scripts/generate_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,19 +748,19 @@ def make_task(topology, auth, ssl, sync, python, extra_tags=(), **extra_vars):
# The pinned pr tasks: the boundary Pythons per server version, stable as CPYTHONS changes.
for version, combos in sorted(SERVER_VERSION_PR_PYTHONS.items()):
for (topology, auth, ssl), python in sorted(combos.items()):
for sync in SYNCS:
tasks.append(
make_task(
topology,
auth,
ssl,
sync,
python,
extra_tags=("pr", version),
VERSION=version,
COVERAGE="1",
)
tasks.extend(
make_task(
topology,
auth,
ssl,
sync,
python,
extra_tags=("pr", version),
VERSION=version,
COVERAGE="1",
)
for sync in SYNCS
)
return tasks


Expand Down
4 changes: 1 addition & 3 deletions bson/son.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ def __new__(cls: type[SON[_Key, _Value]], *args: Any, **kwargs: Any) -> SON[_Key
return instance

def __repr__(self) -> str:
result = []
for key in self.__keys:
result.append(f"({key!r}, {self[key]!r})")
result = [f"({key!r}, {self[key]!r})" for key in self.__keys]
return "SON([{}])".format(", ".join(result))

def __setitem__(self, key: _Key, value: _Value) -> None:
Expand Down
5 changes: 1 addition & 4 deletions gridfs/asynchronous/grid_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -2016,10 +2016,7 @@ async def to_list(self, length: int | None = None) -> list[AsyncGridOut]:
return [x async for x in self] # noqa: C416,RUF100
if length < 1:
raise ValueError("to_list() length must be greater than 0")
ret = []
for _ in range(length):
ret.append(await self.next())
return ret
return [await self.next() for _ in range(length)]

__anext__ = next

Expand Down
5 changes: 1 addition & 4 deletions gridfs/synchronous/grid_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -1996,10 +1996,7 @@ def to_list(self, length: int | None = None) -> list[GridOut]:
return [x for x in self] # noqa: C416,RUF100
if length < 1:
raise ValueError("to_list() length must be greater than 0")
ret = []
for _ in range(length):
ret.append(self.next())
return ret
return [self.next() for _ in range(length)]

__next__ = next

Expand Down
3 changes: 2 additions & 1 deletion pymongo/asynchronous/command_cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,9 @@ async def _next_batch(self, result: list, total: int | None = None) -> bool: #
result.extend(self._data)
self._data.clear()
else:
# A list comprehension here is slower or uses more memory.
for _ in range(min(len(self._data), total)):
result.append(self._data.popleft())
result.append(self._data.popleft()) # noqa: PERF401
return True
else:
return False
Expand Down
3 changes: 2 additions & 1 deletion pymongo/asynchronous/cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,9 @@ async def _next_batch(self, result: list, total: int | None = None) -> bool: #
result.extend(self._data)
self._data.clear()
else:
# A list comprehension here is slower or uses more memory.
for _ in range(min(len(self._data), total)):
result.append(self._data.popleft())
result.append(self._data.popleft()) # noqa: PERF401
return True
else:
return False
Expand Down
39 changes: 21 additions & 18 deletions pymongo/client_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,24 +101,27 @@ def _parse_ssl_options(options: Mapping[str, Any], is_sync: bool) -> tuple[SSLCo
allow_invalid_hostnames = options.get("tlsallowinvalidhostnames", False)
disable_ocsp_endpoint_check = options.get("tlsdisableocspendpointcheck", False)

enabled_tls_opts = []
for opt in (
"tlscertificatekeyfile",
"tlscertificatekeyfilepassword",
"tlscafile",
"tlscrlfile",
):
# Any non-null value of these options implies tls=True.
if options.get(opt):
enabled_tls_opts.append(opt)
for opt in (
"tlsallowinvalidcertificates",
"tlsallowinvalidhostnames",
"tlsdisableocspendpointcheck",
):
# A value of False for these options implies tls=True.
if opt in options and not options[opt]:
enabled_tls_opts.append(opt)
# Any non-null value of these options implies tls=True.
enabled_tls_opts = [
opt
for opt in (
"tlscertificatekeyfile",
"tlscertificatekeyfilepassword",
"tlscafile",
"tlscrlfile",
)
if options.get(opt)
]
# A value of False for these options implies tls=True.
enabled_tls_opts.extend(
opt
for opt in (
"tlsallowinvalidcertificates",
"tlsallowinvalidhostnames",
"tlsdisableocspendpointcheck",
)
if opt in options and not options[opt]
)

if enabled_tls_opts:
if use_tls is None:
Expand Down
3 changes: 1 addition & 2 deletions pymongo/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1120,8 +1120,7 @@ def __new__(cls, *version: int) -> Self:
def _padded(cls, iter: Any, length: int, padding: int = 0) -> list[int]:
as_list = list(iter)
if len(as_list) < length:
for _ in range(length - len(as_list)):
as_list.append(padding)
as_list.extend(padding for _ in range(length - len(as_list)))
return as_list

@classmethod
Expand Down
44 changes: 22 additions & 22 deletions pymongo/encryption_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,17 +324,17 @@ def __init__(

@property
def document(self) -> dict[str, Any]:
doc = {}
for k, v in [
("sparsity", int64.Int64(self.sparsity) if self.sparsity else None),
("trimFactor", self.trim_factor),
("precision", self.precision),
("min", self.min),
("max", self.max),
]:
if v is not None:
doc[k] = v
return doc
return {
k: v
for k, v in [
("sparsity", int64.Int64(self.sparsity) if self.sparsity else None),
("trimFactor", self.trim_factor),
("precision", self.precision),
("min", self.min),
("max", self.max),
]
if v is not None
}


class StringOpts:
Expand Down Expand Up @@ -366,17 +366,17 @@ def __init__(

@property
def document(self) -> dict[str, Any]:
doc = {}
for k, v in [
("substring", self.substring),
("prefix", self.prefix),
("suffix", self.suffix),
("caseSensitive", self.case_sensitive),
("diacriticSensitive", self.diacritic_sensitive),
]:
if v is not None:
doc[k] = v
return doc
return {
k: v
for k, v in [
("substring", self.substring),
("prefix", self.prefix),
("suffix", self.suffix),
("caseSensitive", self.case_sensitive),
("diacriticSensitive", self.diacritic_sensitive),
]
if v is not None
}


class SubstringOpts(TypedDict):
Expand Down
3 changes: 2 additions & 1 deletion pymongo/synchronous/command_cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,9 @@ def _next_batch(self, result: list, total: int | None = None) -> bool: # type:
result.extend(self._data)
self._data.clear()
else:
# A list comprehension here is slower or uses more memory.
for _ in range(min(len(self._data), total)):
result.append(self._data.popleft())
result.append(self._data.popleft()) # noqa: PERF401
return True
else:
return False
Expand Down
3 changes: 2 additions & 1 deletion pymongo/synchronous/cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,9 @@ def _next_batch(self, result: list, total: int | None = None) -> bool: # type:
result.extend(self._data)
self._data.clear()
else:
# A list comprehension here is slower or uses more memory.
for _ in range(min(len(self._data), total)):
result.append(self._data.popleft())
result.append(self._data.popleft()) # noqa: PERF401
return True
else:
return False
Expand Down
3 changes: 1 addition & 2 deletions pymongo/uri_parser_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,5 @@ def _make_options_case_sensitive(options: _CaseInsensitiveDictionary) -> dict[st
if option.lower() in options:
case_sensitive[option] = options[option]
options.pop(option)
for k, v in options.items():
case_sensitive[k] = v
case_sensitive.update(options)
return case_sensitive
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ extend-select = [
"EXE", # flake8-executable
"ASYNC", # flake8-async
"TC", # flake8-type-checking
"PERF", # perflint
"D202", # pydocstyle: no blank lines between docstring and function body.
"D209", # pydocstyle: closing quotes go on their own line.
"D301", # pydocstyle: docstrings containing \ are defined as string literals.
Expand Down
8 changes: 2 additions & 6 deletions test/asynchronous/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,7 @@ async def test_gssapi_threaded(self):
except OperationFailure:
raise SkipTest("User must be able to write.")

threads = []
for _ in range(4):
threads.append(AutoAuthenticateThread(collection))
threads = [AutoAuthenticateThread(collection) for _ in range(4)]
for thread in threads:
thread.start()
for thread in threads:
Expand Down Expand Up @@ -661,9 +659,7 @@ async def test_scram_threaded(self):
# The first thread to call find() will authenticate
client = await self.async_rs_or_single_client()
coll = client.db.coll
threads = []
for _ in range(4):
threads.append(AutoAuthenticateThread(coll))
threads = [AutoAuthenticateThread(coll) for _ in range(4)]
for thread in threads:
thread.start()
for thread in threads:
Expand Down
4 changes: 1 addition & 3 deletions test/asynchronous/test_auth_oidc.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,9 +826,7 @@ async def target():
for _ in range(100):
await client.test.coll.find_one()

tasks = []
for i in range(10):
tasks.append(ConcurrentRunner(target=target))
tasks = [ConcurrentRunner(target=target) for _ in range(10)]
for t in tasks:
await t.start()
for t in tasks:
Expand Down
3 changes: 1 addition & 2 deletions test/asynchronous/test_bulk.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,7 @@ async def test_bulk_max_message_size(self):
{"_id": 3, "l": "s" * (_16_MB - 10000)},
]
# Fill in the remaining ~10000 bytes with small documents.
for i in range(4, 10000):
docs.append({"_id": i})
docs.extend({"_id": i} for i in range(4, 10000))
result = await self.coll.insert_many(docs)
self.assertEqual(len(docs), len(result.inserted_ids))

Expand Down
4 changes: 1 addition & 3 deletions test/asynchronous/test_change_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ async def generate_invalidate_event(self, change_stream):

def generate_unique_collnames(self, numcolls):
"""Generate numcolls collection names unique to a test."""
collnames = []
for idx in range(1, numcolls + 1):
collnames.append(self.id() + "_" + str(idx))
collnames = [self.id() + "_" + str(idx) for idx in range(1, numcolls + 1)]
return collnames

async def get_resume_token(self, invalidate=False):
Expand Down
Loading
Loading