Skip to content

Commit 712bf92

Browse files
committed
run pre-commit
1 parent 85e860a commit 712bf92

File tree

10 files changed

+64
-38
lines changed

10 files changed

+64
-38
lines changed

gridfs/synchronous/grid_file.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def __init__(self, database: Database, collection: str = "fs"):
100100
.. seealso:: The MongoDB documentation on `gridfs <https://dochub.mongodb.org/core/gridfs>`_.
101101
"""
102102
if not isinstance(database, Database):
103-
raise TypeError("database must be an instance of Database")
103+
raise TypeError(f"database must be an instance of Database, not {type(database)}.")
104104

105105
database = _clear_entity_type_registry(database)
106106

@@ -501,7 +501,7 @@ def __init__(
501501
.. seealso:: The MongoDB documentation on `gridfs <https://dochub.mongodb.org/core/gridfs>`_.
502502
"""
503503
if not isinstance(db, Database):
504-
raise TypeError("database must be an instance of Database")
504+
raise TypeError(f"database must be an instance of Database, not {type(db)}.")
505505

506506
db = _clear_entity_type_registry(db)
507507

@@ -1076,7 +1076,9 @@ def __init__(
10761076
:attr:`~pymongo.collection.Collection.write_concern`
10771077
"""
10781078
if not isinstance(root_collection, Collection):
1079-
raise TypeError("root_collection must be an instance of Collection")
1079+
raise TypeError(
1080+
f"root_collection must be an instance of Collection, not {type(root_collection)}."
1081+
)
10801082

10811083
if not root_collection.write_concern.acknowledged:
10821084
raise ConfigurationError("root_collection must use acknowledged write_concern")
@@ -1426,7 +1428,9 @@ def __init__(
14261428
from the server. Metadata is fetched when first needed.
14271429
"""
14281430
if not isinstance(root_collection, Collection):
1429-
raise TypeError("root_collection must be an instance of Collection")
1431+
raise TypeError(
1432+
f"root_collection must be an instance of Collection, not {type(root_collection)}."
1433+
)
14301434
_disallow_transactions(session)
14311435

14321436
root_collection = _clear_entity_type_registry(root_collection)

pymongo/synchronous/auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def _password_digest(username: str, password: str) -> str:
158158
if len(password) == 0:
159159
raise ValueError("password can't be empty")
160160
if not isinstance(username, str):
161-
raise TypeError("username must be an instance of str")
161+
raise TypeError(f"username must be an instance of str, not {type(username)}.")
162162

163163
md5hash = hashlib.md5() # noqa: S324
164164
data = f"{username}:mongo:{password}"

pymongo/synchronous/auth_oidc.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,9 @@ def _get_access_token(self) -> Optional[str]:
213213
)
214214
resp = cb.fetch(context)
215215
if not isinstance(resp, OIDCCallbackResult):
216-
raise ValueError("Callback result must be of type OIDCCallbackResult")
216+
raise ValueError(
217+
f"Callback result must be of type OIDCCallbackResult, not {type(resp)}."
218+
)
217219
self.refresh_token = resp.refresh_token
218220
self.access_token = resp.access_token
219221
self.token_gen_id += 1

pymongo/synchronous/client_session.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,9 @@ def __init__(
309309
)
310310
if max_commit_time_ms is not None:
311311
if not isinstance(max_commit_time_ms, int):
312-
raise TypeError("max_commit_time_ms must be an integer or None")
312+
raise TypeError(
313+
f"max_commit_time_ms must be an integer or None, not {type(max_commit_time_ms)}."
314+
)
313315

314316
@property
315317
def read_concern(self) -> Optional[ReadConcern]:
@@ -897,7 +899,9 @@ def advance_cluster_time(self, cluster_time: Mapping[str, Any]) -> None:
897899
another `ClientSession` instance.
898900
"""
899901
if not isinstance(cluster_time, _Mapping):
900-
raise TypeError("cluster_time must be a subclass of collections.Mapping")
902+
raise TypeError(
903+
f"cluster_time must be a subclass of collections.Mapping, not {type(cluster_time)}."
904+
)
901905
if not isinstance(cluster_time.get("clusterTime"), Timestamp):
902906
raise ValueError("Invalid cluster_time")
903907
self._advance_cluster_time(cluster_time)
@@ -918,7 +922,9 @@ def advance_operation_time(self, operation_time: Timestamp) -> None:
918922
another `ClientSession` instance.
919923
"""
920924
if not isinstance(operation_time, Timestamp):
921-
raise TypeError("operation_time must be an instance of bson.timestamp.Timestamp")
925+
raise TypeError(
926+
f"operation_time must be an instance of bson.timestamp.Timestamp, not {type(operation_time)}."
927+
)
922928
self._advance_operation_time(operation_time)
923929

924930
def _process_response(self, reply: Mapping[str, Any]) -> None:

pymongo/synchronous/collection.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def __init__(
231231
read_concern or database.read_concern,
232232
)
233233
if not isinstance(name, str):
234-
raise TypeError("name must be an instance of str")
234+
raise TypeError(f"name must be an instance of str, not {type(name)}.")
235235
from pymongo.synchronous.database import Database
236236

237237
if not isinstance(database, Database):
@@ -2472,7 +2472,7 @@ def _drop_index(
24722472
name = helpers_shared._gen_index_name(index_or_name)
24732473

24742474
if not isinstance(name, str):
2475-
raise TypeError("index_or_name must be an instance of str or list")
2475+
raise TypeError(f"index_or_name must be an instance of str or list, not {type(name)}.")
24762476

24772477
cmd = {"dropIndexes": self._name, "index": name}
24782478
cmd.update(kwargs)
@@ -3071,7 +3071,7 @@ def rename(
30713071
30723072
"""
30733073
if not isinstance(new_name, str):
3074-
raise TypeError("new_name must be an instance of str")
3074+
raise TypeError(f"new_name must be an instance of str, not {type(new_name)}.")
30753075

30763076
if not new_name or ".." in new_name:
30773077
raise InvalidName("collection names cannot be empty")
@@ -3141,7 +3141,7 @@ def distinct(
31413141
31423142
"""
31433143
if not isinstance(key, str):
3144-
raise TypeError("key must be an instance of str")
3144+
raise TypeError(f"key must be an instance of str, not {type(key)}.")
31453145
cmd = {"distinct": self._name, "key": key}
31463146
if filter is not None:
31473147
if "query" in kwargs:
@@ -3189,7 +3189,7 @@ def _find_and_modify(
31893189
common.validate_is_mapping("filter", filter)
31903190
if not isinstance(return_document, bool):
31913191
raise ValueError(
3192-
"return_document must be ReturnDocument.BEFORE or ReturnDocument.AFTER"
3192+
f"return_document must be ReturnDocument.BEFORE or ReturnDocument.AFTER, not {type(return_document)}."
31933193
)
31943194
collation = validate_collation_or_none(kwargs.pop("collation", None))
31953195
cmd = {"findAndModify": self._name, "query": filter, "new": return_document}

pymongo/synchronous/command_cursor.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ def __init__(
9494
self.batch_size(batch_size)
9595

9696
if not isinstance(max_await_time_ms, int) and max_await_time_ms is not None:
97-
raise TypeError("max_await_time_ms must be an integer or None")
97+
raise TypeError(
98+
f"max_await_time_ms must be an integer or None, not {type(max_await_time_ms)}."
99+
)
98100

99101
def __del__(self) -> None:
100102
self._die_no_lock()
@@ -115,7 +117,7 @@ def batch_size(self, batch_size: int) -> CommandCursor[_DocumentType]:
115117
:param batch_size: The size of each batch of results requested.
116118
"""
117119
if not isinstance(batch_size, int):
118-
raise TypeError("batch_size must be an integer")
120+
raise TypeError(f"batch_size must be an integer, not {type(batch_size)}.")
119121
if batch_size < 0:
120122
raise ValueError("batch_size must be >= 0")
121123

pymongo/synchronous/cursor.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,9 @@ def __init__(
146146
spec: Mapping[str, Any] = filter or {}
147147
validate_is_mapping("filter", spec)
148148
if not isinstance(skip, int):
149-
raise TypeError("skip must be an instance of int")
149+
raise TypeError(f"skip must be an instance of int, not {type(skip)}.")
150150
if not isinstance(limit, int):
151-
raise TypeError("limit must be an instance of int")
151+
raise TypeError(f"limit must be an instance of int, not {type(limit)}.")
152152
validate_boolean("no_cursor_timeout", no_cursor_timeout)
153153
if no_cursor_timeout and not self._explicit_session:
154154
warnings.warn(
@@ -171,7 +171,7 @@ def __init__(
171171
validate_boolean("allow_partial_results", allow_partial_results)
172172
validate_boolean("oplog_replay", oplog_replay)
173173
if not isinstance(batch_size, int):
174-
raise TypeError("batch_size must be an integer")
174+
raise TypeError(f"batch_size must be an integer, not {type(batch_size)}.")
175175
if batch_size < 0:
176176
raise ValueError("batch_size must be >= 0")
177177
# Only set if allow_disk_use is provided by the user, else None.
@@ -388,7 +388,7 @@ def add_option(self, mask: int) -> Cursor[_DocumentType]:
388388
cursor.add_option(2)
389389
"""
390390
if not isinstance(mask, int):
391-
raise TypeError("mask must be an int")
391+
raise TypeError(f"mask must be an int, not {type(mask)}.")
392392
self._check_okay_to_chain()
393393

394394
if mask & _QUERY_OPTIONS["exhaust"]:
@@ -408,7 +408,7 @@ def remove_option(self, mask: int) -> Cursor[_DocumentType]:
408408
cursor.remove_option(2)
409409
"""
410410
if not isinstance(mask, int):
411-
raise TypeError("mask must be an int")
411+
raise TypeError(f"mask must be an int, not {type(mask)}.")
412412
self._check_okay_to_chain()
413413

414414
if mask & _QUERY_OPTIONS["exhaust"]:
@@ -432,7 +432,7 @@ def allow_disk_use(self, allow_disk_use: bool) -> Cursor[_DocumentType]:
432432
.. versionadded:: 3.11
433433
"""
434434
if not isinstance(allow_disk_use, bool):
435-
raise TypeError("allow_disk_use must be a bool")
435+
raise TypeError(f"allow_disk_use must be a bool, not {type(allow_disk_use)}.")
436436
self._check_okay_to_chain()
437437

438438
self._allow_disk_use = allow_disk_use
@@ -451,7 +451,7 @@ def limit(self, limit: int) -> Cursor[_DocumentType]:
451451
.. seealso:: The MongoDB documentation on `limit <https://dochub.mongodb.org/core/limit>`_.
452452
"""
453453
if not isinstance(limit, int):
454-
raise TypeError("limit must be an integer")
454+
raise TypeError(f"limit must be an integer, not {type(limit)}.")
455455
if self._exhaust:
456456
raise InvalidOperation("Can't use limit and exhaust together.")
457457
self._check_okay_to_chain()
@@ -479,7 +479,7 @@ def batch_size(self, batch_size: int) -> Cursor[_DocumentType]:
479479
:param batch_size: The size of each batch of results requested.
480480
"""
481481
if not isinstance(batch_size, int):
482-
raise TypeError("batch_size must be an integer")
482+
raise TypeError(f"batch_size must be an integer, not {type(batch_size)}.")
483483
if batch_size < 0:
484484
raise ValueError("batch_size must be >= 0")
485485
self._check_okay_to_chain()
@@ -499,7 +499,7 @@ def skip(self, skip: int) -> Cursor[_DocumentType]:
499499
:param skip: the number of results to skip
500500
"""
501501
if not isinstance(skip, int):
502-
raise TypeError("skip must be an integer")
502+
raise TypeError(f"skip must be an integer, not {type(skip)}.")
503503
if skip < 0:
504504
raise ValueError("skip must be >= 0")
505505
self._check_okay_to_chain()
@@ -520,7 +520,7 @@ def max_time_ms(self, max_time_ms: Optional[int]) -> Cursor[_DocumentType]:
520520
:param max_time_ms: the time limit after which the operation is aborted
521521
"""
522522
if not isinstance(max_time_ms, int) and max_time_ms is not None:
523-
raise TypeError("max_time_ms must be an integer or None")
523+
raise TypeError(f"max_time_ms must be an integer or None, not {type(max_time_ms)}.")
524524
self._check_okay_to_chain()
525525

526526
self._max_time_ms = max_time_ms
@@ -543,7 +543,9 @@ def max_await_time_ms(self, max_await_time_ms: Optional[int]) -> Cursor[_Documen
543543
.. versionadded:: 3.2
544544
"""
545545
if not isinstance(max_await_time_ms, int) and max_await_time_ms is not None:
546-
raise TypeError("max_await_time_ms must be an integer or None")
546+
raise TypeError(
547+
f"max_await_time_ms must be an integer or None, not {type(max_await_time_ms)}."
548+
)
547549
self._check_okay_to_chain()
548550

549551
# Ignore max_await_time_ms if not tailable or await_data is False.
@@ -677,7 +679,7 @@ def max(self, spec: _Sort) -> Cursor[_DocumentType]:
677679
.. versionadded:: 2.7
678680
"""
679681
if not isinstance(spec, (list, tuple)):
680-
raise TypeError("spec must be an instance of list or tuple")
682+
raise TypeError(f"spec must be an instance of list or tuple, not {type(spec)}.")
681683

682684
self._check_okay_to_chain()
683685
self._max = dict(spec)
@@ -699,7 +701,7 @@ def min(self, spec: _Sort) -> Cursor[_DocumentType]:
699701
.. versionadded:: 2.7
700702
"""
701703
if not isinstance(spec, (list, tuple)):
702-
raise TypeError("spec must be an instance of list or tuple")
704+
raise TypeError(f"spec must be an instance of list or tuple, not {type(spec)}.")
703705

704706
self._check_okay_to_chain()
705707
self._min = dict(spec)

pymongo/synchronous/database.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def __init__(
122122
from pymongo.synchronous.mongo_client import MongoClient
123123

124124
if not isinstance(name, str):
125-
raise TypeError("name must be an instance of str")
125+
raise TypeError(f"name must be an instance of str, not {type(name)}.")
126126

127127
if not isinstance(client, MongoClient):
128128
# This is for compatibility with mocked and subclassed types, such as in Motor.
@@ -1303,7 +1303,7 @@ def drop_collection(
13031303
name = name.name
13041304

13051305
if not isinstance(name, str):
1306-
raise TypeError("name_or_collection must be an instance of str")
1306+
raise TypeError(f"name_or_collection must be an instance of str, not {type(name)}.")
13071307
encrypted_fields = self._get_encrypted_fields(
13081308
{"encryptedFields": encrypted_fields},
13091309
name,
@@ -1367,7 +1367,9 @@ def validate_collection(
13671367
name = name.name
13681368

13691369
if not isinstance(name, str):
1370-
raise TypeError("name_or_collection must be an instance of str or Collection")
1370+
raise TypeError(
1371+
f"name_or_collection must be an instance of str or Collection, not {type(name)}."
1372+
)
13711373
cmd = {"validate": name, "scandata": scandata, "full": full}
13721374
if comment is not None:
13731375
cmd["comment"] = comment

pymongo/synchronous/encryption.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,9 @@ def insert_data_key(self, data_key: bytes) -> Binary:
320320
raw_doc = RawBSONDocument(data_key, _KEY_VAULT_OPTS)
321321
data_key_id = raw_doc.get("_id")
322322
if not isinstance(data_key_id, Binary) or data_key_id.subtype != UUID_SUBTYPE:
323-
raise TypeError("data_key _id must be Binary with a UUID subtype")
323+
raise TypeError(
324+
f"data_key _id must be Binary with a UUID subtype, not {type(data_key_id)}."
325+
)
324326

325327
assert self.key_vault_coll is not None
326328
self.key_vault_coll.insert_one(raw_doc)
@@ -642,7 +644,9 @@ def __init__(
642644
)
643645

644646
if not isinstance(codec_options, CodecOptions):
645-
raise TypeError("codec_options must be an instance of bson.codec_options.CodecOptions")
647+
raise TypeError(
648+
f"codec_options must be an instance of bson.codec_options.CodecOptions, not {type(codec_options)}."
649+
)
646650

647651
if not isinstance(key_vault_client, MongoClient):
648652
# This is for compatibility with mocked and subclassed types, such as in Motor.

pymongo/synchronous/mongo_client.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ def __init__(
748748
if port is None:
749749
port = self.PORT
750750
if not isinstance(port, int):
751-
raise TypeError("port must be an instance of int")
751+
raise TypeError(f"port must be an instance of int, not {type(port)}.")
752752

753753
# _pool_class, _monitor_class, and _condition_class are for deep
754754
# customization of PyMongo, e.g. Motor.
@@ -1965,7 +1965,7 @@ def _close_cursor_now(
19651965
The cursor is closed synchronously on the current thread.
19661966
"""
19671967
if not isinstance(cursor_id, int):
1968-
raise TypeError("cursor_id must be an instance of int")
1968+
raise TypeError(f"cursor_id must be an instance of int, not {type(cursor_id)}.")
19691969

19701970
try:
19711971
if conn_mgr:
@@ -2087,7 +2087,9 @@ def _tmp_session(
20872087
"""If provided session is None, lend a temporary session."""
20882088
if session is not None:
20892089
if not isinstance(session, client_session.ClientSession):
2090-
raise ValueError("'session' argument must be a ClientSession or None.")
2090+
raise ValueError(
2091+
f"'session' argument must be a ClientSession or None, not {type(session)}."
2092+
)
20912093
# Don't call end_session.
20922094
yield session
20932095
return
@@ -2235,7 +2237,9 @@ def drop_database(
22352237
name = name.name
22362238

22372239
if not isinstance(name, str):
2238-
raise TypeError("name_or_database must be an instance of str or a Database")
2240+
raise TypeError(
2241+
f"name_or_database must be an instance of str or a Database, not {type(name)}."
2242+
)
22392243

22402244
with self._conn_for_writes(session, operation=_Op.DROP_DATABASE) as conn:
22412245
self[name]._command(

0 commit comments

Comments
 (0)