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
2 changes: 1 addition & 1 deletion bson/codec_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
UUID_REPRESENTATION_NAMES,
UuidRepresentation,
)
from bson.typings import _DocumentType

_RAW_BSON_DOCUMENT_MARKER = 101

Expand Down Expand Up @@ -242,6 +241,7 @@ class _BaseCodecOptions(NamedTuple):


if TYPE_CHECKING:
from bson.typings import _DocumentType

class CodecOptions(tuple[_DocumentType], Generic[_DocumentType]):
document_class: type[_DocumentType]
Expand Down
6 changes: 4 additions & 2 deletions gridfs/asynchronous/grid_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from collections import abc
from collections.abc import Iterable, Mapping
from types import TracebackType
from typing import Any, NoReturn, Self, cast
from typing import TYPE_CHECKING, Any, NoReturn, Self, cast

from bson.int64 import Int64
from bson.objectid import ObjectId
Expand All @@ -45,7 +45,6 @@
_clear_entity_type_registry,
)
from pymongo import ASCENDING, DESCENDING, WriteConcern, _csot
from pymongo.asynchronous.client_session import AsyncClientSession
from pymongo.asynchronous.collection import AsyncCollection
from pymongo.asynchronous.cursor import AsyncCursor
from pymongo.asynchronous.database import AsyncDatabase
Expand All @@ -62,6 +61,9 @@
from pymongo.helpers_shared import _check_write_command_response
from pymongo.read_preferences import ReadPreference, _ServerMode

if TYPE_CHECKING:
from pymongo.asynchronous.client_session import AsyncClientSession

_IS_SYNC = False


Expand Down
6 changes: 4 additions & 2 deletions gridfs/synchronous/grid_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from collections import abc
from collections.abc import Iterable, Mapping
from types import TracebackType
from typing import Any, NoReturn, Self, cast
from typing import TYPE_CHECKING, Any, NoReturn, Self, cast

from bson.int64 import Int64
from bson.objectid import ObjectId
Expand Down Expand Up @@ -56,12 +56,14 @@
)
from pymongo.helpers_shared import _check_write_command_response
from pymongo.read_preferences import ReadPreference, _ServerMode
from pymongo.synchronous.client_session import ClientSession
from pymongo.synchronous.collection import Collection
from pymongo.synchronous.cursor import Cursor
from pymongo.synchronous.database import Database
from pymongo.synchronous.helpers import next

if TYPE_CHECKING:
from pymongo.synchronous.client_session import ClientSession

_IS_SYNC = True


Expand Down
2 changes: 1 addition & 1 deletion pymongo/_client_bulk_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
from pymongo.errors import ClientBulkWriteException, OperationFailure
from pymongo.helpers_shared import _get_wce_doc
from pymongo.message import _ClientBulkWriteContext
from pymongo.write_concern import WriteConcern

if TYPE_CHECKING:
from pymongo.typings import _AgnosticMongoClient, _DocumentOut, _Pipeline
from pymongo.write_concern import WriteConcern


def _merge_command(
Expand Down
2 changes: 1 addition & 1 deletion pymongo/asynchronous/_kms_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
from pymongo.common import CONNECT_TIMEOUT
from pymongo.errors import ConfigurationError
from pymongo.helpers_shared import _get_timeout_details
from pymongo.pool_options import PoolOptions
from pymongo.pool_shared import (
_async_configured_socket,
_async_wrap_socket_tls,
Expand All @@ -45,6 +44,7 @@
)

if TYPE_CHECKING:
from pymongo.pool_options import PoolOptions
from pymongo.pyopenssl_context import _sslConn
from pymongo.typings import _Address

Expand Down
2 changes: 1 addition & 1 deletion pymongo/asynchronous/bulk.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

from pymongo import _csot
from pymongo._telemetry import _generate_op_id_or_none
from pymongo.asynchronous.client_session import AsyncClientSession
from pymongo.asynchronous.command_runner import (
run_bulk_write_command,
)
Expand Down Expand Up @@ -57,6 +56,7 @@
from pymongo.write_concern import WriteConcern

if TYPE_CHECKING:
from pymongo.asynchronous.client_session import AsyncClientSession
from pymongo.asynchronous.collection import AsyncCollection
from pymongo.asynchronous.mongo_client import AsyncMongoClient
from pymongo.asynchronous.pool import AsyncConnection
Expand Down
4 changes: 2 additions & 2 deletions pymongo/asynchronous/client_bulk.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

from pymongo import _csot
from pymongo._telemetry import _generate_op_id_or_none
from pymongo.asynchronous.client_session import AsyncClientSession
from pymongo.asynchronous.collection import AsyncCollection
from pymongo.asynchronous.command_cursor import AsyncCommandCursor
from pymongo.asynchronous.command_runner import (
Expand All @@ -39,8 +38,10 @@
from pymongo.asynchronous.helpers import _handle_reauth

if TYPE_CHECKING:
from pymongo.asynchronous.client_session import AsyncClientSession
from pymongo.asynchronous.mongo_client import AsyncMongoClient
from pymongo.asynchronous.pool import AsyncConnection
from pymongo.write_concern import WriteConcern
from pymongo._client_bulk_shared import (
_AgnosticClientBulkBase,
_merge_command,
Expand Down Expand Up @@ -68,7 +69,6 @@
InsertOneResult,
UpdateResult,
)
from pymongo.write_concern import WriteConcern

_IS_SYNC = False

Expand Down
4 changes: 2 additions & 2 deletions pymongo/asynchronous/client_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,15 @@
PyMongoError,
WTimeoutError,
)
from pymongo.read_concern import ReadConcern
from pymongo.read_preferences import _ServerMode
from pymongo.write_concern import WriteConcern

if TYPE_CHECKING:
from types import TracebackType

from pymongo.asynchronous.mongo_client import AsyncMongoClient
from pymongo.asynchronous.pool import AsyncConnection
from pymongo.read_concern import ReadConcern
from pymongo.read_preferences import _ServerMode

_IS_SYNC = False

Expand Down
2 changes: 1 addition & 1 deletion pymongo/asynchronous/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
from bson.objectid import ObjectId
from bson.raw_bson import RawBSONDocument
from bson.son import SON
from bson.timestamp import Timestamp
from pymongo import ASCENDING, _csot, common, helpers_shared, message
from pymongo.asynchronous.aggregation import (
_CollectionAggregationCommand,
Expand Down Expand Up @@ -125,6 +124,7 @@ class ReturnDocument:

if TYPE_CHECKING:
import bson
from bson.timestamp import Timestamp
from pymongo.asynchronous.aggregation import _AggregationCommand
from pymongo.asynchronous.client_session import AsyncClientSession
from pymongo.asynchronous.database import AsyncDatabase
Expand Down
2 changes: 1 addition & 1 deletion pymongo/asynchronous/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

from bson.codec_options import DEFAULT_CODEC_OPTIONS, CodecOptions
from bson.dbref import DBRef
from bson.timestamp import Timestamp
from pymongo import _csot, common
from pymongo.asynchronous.aggregation import _DatabaseAggregationCommand
from pymongo.asynchronous.change_stream import AsyncDatabaseChangeStream
Expand All @@ -45,6 +44,7 @@
if TYPE_CHECKING:
import bson
import bson.codec_options
from bson.timestamp import Timestamp
from pymongo.asynchronous.client_session import AsyncClientSession
from pymongo.asynchronous.mongo_client import AsyncMongoClient
from pymongo.asynchronous.pool import AsyncConnection
Expand Down
7 changes: 4 additions & 3 deletions pymongo/asynchronous/encryption.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,8 @@
from bson.codec_options import CodecOptions
from bson.raw_bson import DEFAULT_RAW_BSON_OPTIONS, RawBSONDocument, _inflate_bson
from pymongo import _csot, _op_id
from pymongo._kms_connect_shared import AsyncKMSConnectCallback
from pymongo.asynchronous._kms_connect import _KMS_CONNECT_TIMEOUT, _connect_kms
from pymongo.asynchronous.collection import AsyncCollection
from pymongo.asynchronous.cursor import AsyncCursor
from pymongo.asynchronous.database import AsyncDatabase
from pymongo.asynchronous.mongo_client import AsyncMongoClient
from pymongo.daemon import _spawn_daemon
Expand Down Expand Up @@ -87,7 +85,6 @@
_raise_connection_failure,
)
from pymongo.read_concern import ReadConcern
from pymongo.results import DeleteResult
from pymongo.ssl_support import BLOCKING_IO_ERRORS, get_ssl_context
from pymongo.typings import _DocumentType, _DocumentTypeArg
from pymongo.uri_parser_shared import _parse_kms_tls_options, parse_host
Expand All @@ -96,6 +93,10 @@
if TYPE_CHECKING:
from pymongocrypt.mongocrypt import MongoCryptKmsContext

from pymongo._kms_connect_shared import AsyncKMSConnectCallback
from pymongo.asynchronous.cursor import AsyncCursor
from pymongo.results import DeleteResult


_IS_SYNC = False

Expand Down
4 changes: 2 additions & 2 deletions pymongo/asynchronous/mongo_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
)

from bson.codec_options import DEFAULT_CODEC_OPTIONS, CodecOptions, TypeRegistry
from bson.timestamp import Timestamp
from pymongo import _csot, _op_id, common, helpers_shared, periodic_executor
from pymongo.asynchronous import client_session, database, uri_parser
from pymongo.asynchronous.change_stream import AsyncChangeStream, AsyncClusterChangeStream
Expand Down Expand Up @@ -107,7 +106,6 @@
_Op,
)
from pymongo.read_preferences import ReadPreference, _ServerMode
from pymongo.results import ClientBulkWriteResult
from pymongo.server_description import ServerDescription
from pymongo.server_selectors import writable_server_selector
from pymongo.server_type import SERVER_TYPE
Expand Down Expand Up @@ -136,6 +134,7 @@
from types import TracebackType

from bson.objectid import ObjectId
from bson.timestamp import Timestamp
from pymongo.asynchronous.bulk import _AsyncBulk
from pymongo.asynchronous.client_session import AsyncClientSession
from pymongo.asynchronous.cursor_base import _ConnectionManager
Expand All @@ -145,6 +144,7 @@
from pymongo.client_session_shared import _ServerSession
from pymongo.read_concern import ReadConcern
from pymongo.response import Response
from pymongo.results import ClientBulkWriteResult
from pymongo.server_selectors import Selection


Expand Down
4 changes: 3 additions & 1 deletion pymongo/asynchronous/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@
ConnectionClosedReason,
)
from pymongo.network_layer import AsyncNetworkingInterface, async_receive_message, async_sendall
from pymongo.pool_options import PoolOptions

# Needed for backwards-compatible imports from pool.py.
from pymongo.pool_options import PoolOptions # noqa: TC001
from pymongo.pool_shared import (
_UNDO_OPERATION_COUNT,
_UNDO_PENDING,
Expand Down
9 changes: 6 additions & 3 deletions pymongo/asynchronous/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@

import threading
from collections.abc import Callable, Collection
from typing import TYPE_CHECKING

from bson.objectid import ObjectId
from pymongo import common
from pymongo.asynchronous import monitor, pool
from pymongo.asynchronous.pool import Pool
from pymongo.common import LOCAL_THRESHOLD_MS, SERVER_SELECTION_TIMEOUT
from pymongo.pool_options import PoolOptions
from pymongo.settings_shared import _BaseTopologySettings
from pymongo.topology_description import _ServerSelector

if TYPE_CHECKING:
from bson.objectid import ObjectId
from pymongo.pool_options import PoolOptions
from pymongo.topology_description import _ServerSelector

_IS_SYNC = False

Expand Down
4 changes: 2 additions & 2 deletions pymongo/change_stream_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
from collections.abc import Mapping
from typing import TYPE_CHECKING, Any, Generic, TypeVar, cast

from bson import CodecOptions
from bson.raw_bson import RawBSONDocument
from bson.timestamp import Timestamp
from pymongo import common
from pymongo.collation import validate_collation_or_none
from pymongo.errors import (
Expand All @@ -34,6 +32,8 @@
from pymongo.typings import _DocumentType

if TYPE_CHECKING:
from bson import CodecOptions
from bson.timestamp import Timestamp
from pymongo.typings import (
_AgnosticClientSession,
_AgnosticCollection,
Expand Down
2 changes: 1 addition & 1 deletion pymongo/encryption_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
AsyncKMSConnectCallback,
HTTPProxyKMSConnect,
KMSConnectCallback,
KMSConnectContext,
KMSConnectContext, # noqa: TC001
)
from pymongo.common import check_for_min_version, validate_is_mapping
from pymongo.errors import ConfigurationError
Expand Down
6 changes: 4 additions & 2 deletions pymongo/encryption_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import contextlib
import enum
from collections.abc import Iterator
from typing import Any
from typing import TYPE_CHECKING, Any

try:
from pymongocrypt.mongocrypt import MongoCryptOptions # type:ignore[import-untyped]
Expand All @@ -28,7 +28,9 @@

from bson.errors import BSONError
from pymongo.errors import EncryptionError
from pymongo.results import BulkWriteResult

if TYPE_CHECKING:
from pymongo.results import BulkWriteResult


@contextlib.contextmanager
Expand Down
6 changes: 4 additions & 2 deletions pymongo/hello.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@
import datetime
import itertools
from collections.abc import Mapping
from typing import Any, Generic
from typing import TYPE_CHECKING, Any, Generic

from bson.objectid import ObjectId
from pymongo import common
from pymongo.server_type import SERVER_TYPE
from pymongo.typings import ClusterTime, _DocumentType

if TYPE_CHECKING:
from bson.objectid import ObjectId


def _get_server_type(doc: Mapping[str, Any]) -> int:
"""Determine the server type from a hello response."""
Expand Down
2 changes: 1 addition & 1 deletion pymongo/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
_inflate_bson,
)
from pymongo.common import MONGOS_EXHAUST_WIRE_VERSION
from pymongo.monitoring import _EventListeners

try:
from pymongo import _cmessage # type: ignore[attr-defined]
Expand All @@ -59,6 +58,7 @@

if TYPE_CHECKING:
from pymongo.compression_support import SnappyContext, ZlibContext, ZstdContext
from pymongo.monitoring import _EventListeners
from pymongo.read_concern import ReadConcern
from pymongo.typings import (
_Address,
Expand Down
4 changes: 2 additions & 2 deletions pymongo/monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,16 +193,16 @@ def connection_checked_in(self, event):
from collections.abc import Mapping, Sequence
from typing import TYPE_CHECKING, Any

from bson.objectid import ObjectId
from pymongo.hello import Hello, HelloCompat
from pymongo.helpers_shared import _SENSITIVE_COMMANDS, _handle_exception
from pymongo.typings import _Address, _DocumentOut

if TYPE_CHECKING:
from datetime import timedelta

from bson.objectid import ObjectId
from pymongo.server_description import ServerDescription
from pymongo.topology_description import TopologyDescription
from pymongo.typings import _Address, _DocumentOut


_Listeners = namedtuple(
Expand Down
Loading
Loading