Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion pymongo/asynchronous/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def __init__(
from pymongo.asynchronous.database import AsyncDatabase

if not isinstance(database, AsyncDatabase):
if not any(cls.__name__ == "AsyncDatabase" for cls in database.__mro__):
if not any(cls.__name__ == "AsyncDatabase" for cls in type(database).__mro__):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a comment explaining why we added this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: please add a period at the end of all the comments.

raise TypeError(f"AsyncDatabase required but given {type(database).__name__}")

if not name or ".." in name:
Expand Down
2 changes: 1 addition & 1 deletion pymongo/asynchronous/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def __init__(
raise TypeError("name must be an instance of str")

if not isinstance(client, AsyncMongoClient):
if not any(cls.__name__ == "AsyncMongoClient" for cls in client.__mro__):
if not any(cls.__name__ == "AsyncMongoClient" for cls in type(client).__mro__):
raise TypeError(f"AsyncMongoClient required but given {type(client).__name__}")

if name != "$external":
Expand Down
6 changes: 4 additions & 2 deletions pymongo/asynchronous/encryption.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,9 @@ def __init__(
raise TypeError("codec_options must be an instance of bson.codec_options.CodecOptions")

if not isinstance(key_vault_client, AsyncMongoClient):
if not any(cls.__name__ == "AsyncMongoClient" for cls in key_vault_client.__mro__):
if not any(
cls.__name__ == "AsyncMongoClient" for cls in type(key_vault_client).__mro__
):
raise TypeError(
f"AsyncMongoClient required but given {type(key_vault_client).__name__}"
)
Expand Down Expand Up @@ -688,7 +690,7 @@ async def create_encrypted_collection(

"""
if not isinstance(database, AsyncDatabase):
if not any(cls.__name__ == "AsyncDatabase" for cls in database.__mro__):
if not any(cls.__name__ == "AsyncDatabase" for cls in type(database).__mro__):
raise TypeError(f"AsyncDatabase required but given {type(database).__name__}")

encrypted_fields = deepcopy(encrypted_fields)
Expand Down
2 changes: 1 addition & 1 deletion pymongo/asynchronous/mongo_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2446,7 +2446,7 @@ def __init__(
self, client: AsyncMongoClient, server: Server, session: Optional[AsyncClientSession]
):
if not isinstance(client, AsyncMongoClient):
if not any(cls.__name__ == "AsyncMongoClient" for cls in client.__mro__):
if not any(cls.__name__ == "AsyncMongoClient" for cls in type(client).__mro__):
raise TypeError(f"AsyncMongoClient required but given {type(client).__name__}")

self.client = client
Expand Down
2 changes: 1 addition & 1 deletion pymongo/synchronous/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def __init__(
from pymongo.synchronous.database import Database

if not isinstance(database, Database):
if not any(cls.__name__ == "Database" for cls in database.__mro__):
if not any(cls.__name__ == "Database" for cls in type(database).__mro__):
raise TypeError(f"Database required but given {type(database).__name__}")

if not name or ".." in name:
Expand Down
2 changes: 1 addition & 1 deletion pymongo/synchronous/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def __init__(
raise TypeError("name must be an instance of str")

if not isinstance(client, MongoClient):
if not any(cls.__name__ == "MongoClient" for cls in client.__mro__):
if not any(cls.__name__ == "MongoClient" for cls in type(client).__mro__):
raise TypeError(f"MongoClient required but given {type(client).__name__}")

if name != "$external":
Expand Down
4 changes: 2 additions & 2 deletions pymongo/synchronous/encryption.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ def __init__(
raise TypeError("codec_options must be an instance of bson.codec_options.CodecOptions")

if not isinstance(key_vault_client, MongoClient):
if not any(cls.__name__ == "MongoClient" for cls in key_vault_client.__mro__):
if not any(cls.__name__ == "MongoClient" for cls in type(key_vault_client).__mro__):
raise TypeError(f"MongoClient required but given {type(key_vault_client).__name__}")

self._kms_providers = kms_providers
Expand Down Expand Up @@ -684,7 +684,7 @@ def create_encrypted_collection(

"""
if not isinstance(database, Database):
if not any(cls.__name__ == "Database" for cls in database.__mro__):
if not any(cls.__name__ == "Database" for cls in type(database).__mro__):
raise TypeError(f"Database required but given {type(database).__name__}")

encrypted_fields = deepcopy(encrypted_fields)
Expand Down
2 changes: 1 addition & 1 deletion pymongo/synchronous/mongo_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2434,7 +2434,7 @@ class _MongoClientErrorHandler:

def __init__(self, client: MongoClient, server: Server, session: Optional[ClientSession]):
if not isinstance(client, MongoClient):
if not any(cls.__name__ == "MongoClient" for cls in client.__mro__):
if not any(cls.__name__ == "MongoClient" for cls in type(client).__mro__):
raise TypeError(f"MongoClient required but given {type(client).__name__}")

self.client = client
Expand Down
Loading