diff --git a/bson/__init__.py b/bson/__init__.py index 41865d2fd9..34b7f7a2f9 100644 --- a/bson/__init__.py +++ b/bson/__init__.py @@ -82,13 +82,12 @@ from codecs import utf_8_decode as _utf_8_decode from codecs import utf_8_encode as _utf_8_encode from collections import abc as _abc -from collections.abc import Generator, Iterator, Mapping, MutableMapping, Sequence +from collections.abc import Callable, Generator, Iterator, Mapping, MutableMapping, Sequence from typing import ( IO, TYPE_CHECKING, Any, BinaryIO, - Callable, NoReturn, Optional, TypeVar, diff --git a/bson/codec_options.py b/bson/codec_options.py index 622d317f44..df18b9c715 100644 --- a/bson/codec_options.py +++ b/bson/codec_options.py @@ -19,12 +19,11 @@ import abc import datetime import enum -from collections.abc import Iterable, Mapping +from collections.abc import Callable, Iterable, Mapping from collections.abc import MutableMapping as _MutableMapping from typing import ( TYPE_CHECKING, Any, - Callable, Generic, NamedTuple, Optional, diff --git a/bson/json_util.py b/bson/json_util.py index 8d84184487..01f9f0497d 100644 --- a/bson/json_util.py +++ b/bson/json_util.py @@ -111,11 +111,10 @@ import math import re import uuid -from collections.abc import Mapping, MutableMapping, Sequence +from collections.abc import Callable, Mapping, MutableMapping, Sequence from typing import ( TYPE_CHECKING, Any, - Callable, Optional, Union, cast, diff --git a/pymongo/_csot.py b/pymongo/_csot.py index f586c21a9f..e7c6e4e3fa 100644 --- a/pymongo/_csot.py +++ b/pymongo/_csot.py @@ -20,10 +20,10 @@ import inspect import time from collections import deque -from collections.abc import MutableMapping +from collections.abc import Callable, MutableMapping from contextlib import AbstractContextManager from contextvars import ContextVar, Token -from typing import TYPE_CHECKING, Any, Callable, Optional, TypeVar, cast +from typing import TYPE_CHECKING, Any, Optional, TypeVar, cast if TYPE_CHECKING: from pymongo.write_concern import WriteConcern diff --git a/pymongo/_kms_connect_shared.py b/pymongo/_kms_connect_shared.py index 47665181ee..634619dcdf 100644 --- a/pymongo/_kms_connect_shared.py +++ b/pymongo/_kms_connect_shared.py @@ -30,9 +30,9 @@ import threading import time import urllib.parse -from collections.abc import Awaitable, Mapping +from collections.abc import Awaitable, Callable, Mapping from dataclasses import dataclass -from typing import Any, Callable, Optional +from typing import Any, Optional from pymongo.errors import ConfigurationError diff --git a/pymongo/asynchronous/auth.py b/pymongo/asynchronous/auth.py index 0003bb60d7..2a50ff7ce8 100644 --- a/pymongo/asynchronous/auth.py +++ b/pymongo/asynchronous/auth.py @@ -21,11 +21,10 @@ import hmac import socket from base64 import standard_b64decode, standard_b64encode -from collections.abc import Coroutine, Mapping +from collections.abc import Callable, Coroutine, Mapping from typing import ( TYPE_CHECKING, Any, - Callable, ) from urllib.parse import quote diff --git a/pymongo/asynchronous/client_session.py b/pymongo/asynchronous/client_session.py index 61606ead75..531d098f5a 100644 --- a/pymongo/asynchronous/client_session.py +++ b/pymongo/asynchronous/client_session.py @@ -138,13 +138,12 @@ import asyncio import random import time -from collections.abc import Awaitable +from collections.abc import Awaitable, Callable from contextlib import AbstractAsyncContextManager from contextvars import ContextVar, Token from typing import ( TYPE_CHECKING, Any, - Callable, Optional, TypeVar, ) diff --git a/pymongo/asynchronous/collection.py b/pymongo/asynchronous/collection.py index 924635d7dc..55c5d98f09 100644 --- a/pymongo/asynchronous/collection.py +++ b/pymongo/asynchronous/collection.py @@ -18,11 +18,18 @@ import warnings from collections import abc -from collections.abc import Coroutine, Iterable, Iterator, Mapping, MutableMapping, Sequence +from collections.abc import ( + Callable, + Coroutine, + Iterable, + Iterator, + Mapping, + MutableMapping, + Sequence, +) from typing import ( TYPE_CHECKING, Any, - Callable, Generic, NoReturn, Optional, diff --git a/pymongo/asynchronous/command_runner.py b/pymongo/asynchronous/command_runner.py index 48801f2059..63f7c8afe8 100644 --- a/pymongo/asynchronous/command_runner.py +++ b/pymongo/asynchronous/command_runner.py @@ -37,11 +37,10 @@ import datetime import time -from collections.abc import Mapping, MutableMapping, Sequence +from collections.abc import Callable, Mapping, MutableMapping, Sequence from typing import ( TYPE_CHECKING, Any, - Callable, Optional, Union, cast, diff --git a/pymongo/asynchronous/helpers.py b/pymongo/asynchronous/helpers.py index ed5b76c554..26b4ade00a 100644 --- a/pymongo/asynchronous/helpers.py +++ b/pymongo/asynchronous/helpers.py @@ -20,9 +20,9 @@ import builtins import functools import socket +from collections.abc import Callable from typing import ( Any, - Callable, TypeVar, cast, ) diff --git a/pymongo/asynchronous/mongo_client.py b/pymongo/asynchronous/mongo_client.py index fcfe94fd2f..e1837c05ed 100644 --- a/pymongo/asynchronous/mongo_client.py +++ b/pymongo/asynchronous/mongo_client.py @@ -40,11 +40,18 @@ import warnings import weakref from collections import defaultdict -from collections.abc import AsyncGenerator, Collection, Coroutine, Mapping, MutableMapping, Sequence +from collections.abc import ( + AsyncGenerator, + Callable, + Collection, + Coroutine, + Mapping, + MutableMapping, + Sequence, +) from typing import ( TYPE_CHECKING, Any, - Callable, Generic, NoReturn, Optional, diff --git a/pymongo/asynchronous/settings.py b/pymongo/asynchronous/settings.py index 4bc5f05f28..cc397ea411 100644 --- a/pymongo/asynchronous/settings.py +++ b/pymongo/asynchronous/settings.py @@ -17,8 +17,8 @@ from __future__ import annotations import threading -from collections.abc import Collection -from typing import Callable, Optional +from collections.abc import Callable, Collection +from typing import Optional from bson.objectid import ObjectId from pymongo import common diff --git a/pymongo/asynchronous/srv_resolver.py b/pymongo/asynchronous/srv_resolver.py index 262e9107ce..18b0ad1c6f 100644 --- a/pymongo/asynchronous/srv_resolver.py +++ b/pymongo/asynchronous/srv_resolver.py @@ -18,7 +18,8 @@ import ipaddress import random -from typing import TYPE_CHECKING, Any, Callable, Optional, Union +from collections.abc import Callable +from typing import TYPE_CHECKING, Any, Optional, Union from pymongo._psl import SPECIAL_USE_LABELS, _to_punycode, is_public_suffix from pymongo._telemetry import log_srv_monitor_invalid_host diff --git a/pymongo/asynchronous/topology.py b/pymongo/asynchronous/topology.py index 8f1b4b1a21..ea49537707 100644 --- a/pymongo/asynchronous/topology.py +++ b/pymongo/asynchronous/topology.py @@ -24,9 +24,9 @@ import time import warnings import weakref -from collections.abc import Mapping +from collections.abc import Callable, Mapping from pathlib import Path -from typing import TYPE_CHECKING, Any, Callable, Optional, cast +from typing import TYPE_CHECKING, Any, Optional, cast from pymongo import _csot, common, helpers_shared, periodic_executor from pymongo._telemetry import ( diff --git a/pymongo/asynchronous/uri_parser.py b/pymongo/asynchronous/uri_parser.py index c42add6ae8..a904c4d283 100644 --- a/pymongo/asynchronous/uri_parser.py +++ b/pymongo/asynchronous/uri_parser.py @@ -17,7 +17,8 @@ from __future__ import annotations -from typing import Any, Callable, Optional +from collections.abc import Callable +from typing import Any, Optional from pymongo.asynchronous.srv_resolver import _SrvResolver from pymongo.common import SRV_SERVICE_NAME, _CaseInsensitiveDictionary diff --git a/pymongo/auth_oidc_shared.py b/pymongo/auth_oidc_shared.py index a774c85c0e..c81bfd5e7d 100644 --- a/pymongo/auth_oidc_shared.py +++ b/pymongo/auth_oidc_shared.py @@ -19,9 +19,9 @@ import abc import os -from collections.abc import Mapping, MutableMapping +from collections.abc import Callable, Mapping, MutableMapping from dataclasses import dataclass, field -from typing import TYPE_CHECKING, Any, Callable, Optional +from typing import TYPE_CHECKING, Any, Optional from urllib.parse import quote import bson diff --git a/pymongo/auth_shared.py b/pymongo/auth_shared.py index 1d624bd8c4..0cf3cd19b6 100644 --- a/pymongo/auth_shared.py +++ b/pymongo/auth_shared.py @@ -22,8 +22,8 @@ import typing from base64 import standard_b64encode from collections import namedtuple -from collections.abc import Mapping, MutableMapping -from typing import TYPE_CHECKING, Any, Callable, Optional, cast +from collections.abc import Callable, Mapping, MutableMapping +from typing import TYPE_CHECKING, Any, Optional, cast from bson import Binary from pymongo.auth_oidc_shared import ( diff --git a/pymongo/client_session_shared.py b/pymongo/client_session_shared.py index a5b057298d..16e6794a8d 100644 --- a/pymongo/client_session_shared.py +++ b/pymongo/client_session_shared.py @@ -19,11 +19,10 @@ import collections import time import uuid -from collections.abc import Mapping, MutableMapping +from collections.abc import Callable, Mapping, MutableMapping from typing import ( TYPE_CHECKING, Any, - Callable, Generic, NoReturn, Optional, diff --git a/pymongo/common.py b/pymongo/common.py index ce4379b507..224b762fa5 100644 --- a/pymongo/common.py +++ b/pymongo/common.py @@ -20,13 +20,12 @@ import datetime import warnings from collections import OrderedDict, abc -from collections.abc import Iterator, Mapping, MutableMapping, Sequence +from collections.abc import Callable, Iterator, Mapping, MutableMapping, Sequence from difflib import get_close_matches from importlib.metadata import requires, version from typing import ( TYPE_CHECKING, Any, - Callable, NoReturn, Optional, Union, diff --git a/pymongo/encryption_options.py b/pymongo/encryption_options.py index fdabecbbcb..f02b28e9b8 100644 --- a/pymongo/encryption_options.py +++ b/pymongo/encryption_options.py @@ -20,8 +20,8 @@ from __future__ import annotations import warnings -from collections.abc import Mapping -from typing import TYPE_CHECKING, Any, Callable, Optional, TypedDict +from collections.abc import Callable, Mapping +from typing import TYPE_CHECKING, Any, Optional, TypedDict from pymongo.uri_parser_shared import _parse_kms_tls_options diff --git a/pymongo/message.py b/pymongo/message.py index be91726f37..32fd83d636 100644 --- a/pymongo/message.py +++ b/pymongo/message.py @@ -24,12 +24,11 @@ import random import struct -from collections.abc import Iterable, Mapping, MutableMapping +from collections.abc import Callable, Iterable, Mapping, MutableMapping from io import BytesIO as _BytesIO from typing import ( TYPE_CHECKING, Any, - Callable, NoReturn, Optional, Union, diff --git a/pymongo/mongo_client_shared.py b/pymongo/mongo_client_shared.py index 2951af5db1..f2f8629a1c 100644 --- a/pymongo/mongo_client_shared.py +++ b/pymongo/mongo_client_shared.py @@ -16,8 +16,8 @@ from __future__ import annotations -from collections.abc import Mapping -from typing import TYPE_CHECKING, Any, Callable, Generic, Optional, TypeVar, Union, cast +from collections.abc import Callable, Mapping +from typing import TYPE_CHECKING, Any, Generic, Optional, TypeVar, Union, cast from pymongo import _csot from pymongo._telemetry import _generate_op_id_or_none, log_command_retry diff --git a/pymongo/network_layer.py b/pymongo/network_layer.py index 3f5afc1262..5425a68503 100644 --- a/pymongo/network_layer.py +++ b/pymongo/network_layer.py @@ -24,10 +24,10 @@ import sys import time from asyncio import AbstractEventLoop, BaseTransport, BufferedProtocol, Future, Transport +from collections.abc import Callable from typing import ( TYPE_CHECKING, Any, - Callable, Optional, Union, ) diff --git a/pymongo/pyopenssl_context.py b/pymongo/pyopenssl_context.py index c33603dea3..452912d686 100644 --- a/pymongo/pyopenssl_context.py +++ b/pymongo/pyopenssl_context.py @@ -24,9 +24,10 @@ import ssl as _stdlibssl import sys as _sys import time as _time +from collections.abc import Callable from errno import EINTR as _EINTR from ipaddress import ip_address as _ip_address -from typing import TYPE_CHECKING, Any, Callable, Optional, TypeVar, Union +from typing import TYPE_CHECKING, Any, Optional, TypeVar, Union import cryptography.x509 as x509 import service_identity diff --git a/pymongo/settings_shared.py b/pymongo/settings_shared.py index bf45c40334..65e744be2e 100644 --- a/pymongo/settings_shared.py +++ b/pymongo/settings_shared.py @@ -18,8 +18,8 @@ import threading import traceback -from collections.abc import Collection -from typing import Any, Callable, Generic, Optional, TypeVar, Union +from collections.abc import Callable, Collection +from typing import Any, Generic, Optional, TypeVar, Union from bson.objectid import ObjectId from pymongo import common diff --git a/pymongo/synchronous/auth.py b/pymongo/synchronous/auth.py index d8d08306d2..e0b24ca4e2 100644 --- a/pymongo/synchronous/auth.py +++ b/pymongo/synchronous/auth.py @@ -21,11 +21,10 @@ import hmac import socket from base64 import standard_b64decode, standard_b64encode -from collections.abc import Mapping +from collections.abc import Callable, Mapping from typing import ( TYPE_CHECKING, Any, - Callable, ) from urllib.parse import quote diff --git a/pymongo/synchronous/client_session.py b/pymongo/synchronous/client_session.py index b536e053c8..53631139ed 100644 --- a/pymongo/synchronous/client_session.py +++ b/pymongo/synchronous/client_session.py @@ -137,12 +137,12 @@ import random import time +from collections.abc import Callable from contextlib import AbstractContextManager from contextvars import ContextVar, Token from typing import ( TYPE_CHECKING, Any, - Callable, Optional, TypeVar, ) diff --git a/pymongo/synchronous/collection.py b/pymongo/synchronous/collection.py index 931001e179..eccd7c57b9 100644 --- a/pymongo/synchronous/collection.py +++ b/pymongo/synchronous/collection.py @@ -18,11 +18,17 @@ import warnings from collections import abc -from collections.abc import Iterable, Iterator, Mapping, MutableMapping, Sequence +from collections.abc import ( + Callable, + Iterable, + Iterator, + Mapping, + MutableMapping, + Sequence, +) from typing import ( TYPE_CHECKING, Any, - Callable, Generic, NoReturn, Optional, diff --git a/pymongo/synchronous/command_runner.py b/pymongo/synchronous/command_runner.py index 2aa62e87ad..9f37ce0308 100644 --- a/pymongo/synchronous/command_runner.py +++ b/pymongo/synchronous/command_runner.py @@ -37,11 +37,10 @@ import datetime import time -from collections.abc import Mapping, MutableMapping, Sequence +from collections.abc import Callable, Mapping, MutableMapping, Sequence from typing import ( TYPE_CHECKING, Any, - Callable, Optional, Union, cast, diff --git a/pymongo/synchronous/helpers.py b/pymongo/synchronous/helpers.py index 3acf43ff5f..695259c952 100644 --- a/pymongo/synchronous/helpers.py +++ b/pymongo/synchronous/helpers.py @@ -20,9 +20,9 @@ import builtins import functools import socket +from collections.abc import Callable from typing import ( Any, - Callable, TypeVar, cast, ) diff --git a/pymongo/synchronous/mongo_client.py b/pymongo/synchronous/mongo_client.py index 52ca029d26..d9816b07a2 100644 --- a/pymongo/synchronous/mongo_client.py +++ b/pymongo/synchronous/mongo_client.py @@ -40,11 +40,17 @@ import warnings import weakref from collections import defaultdict -from collections.abc import Collection, Generator, Mapping, MutableMapping, Sequence +from collections.abc import ( + Callable, + Collection, + Generator, + Mapping, + MutableMapping, + Sequence, +) from typing import ( TYPE_CHECKING, Any, - Callable, Generic, NoReturn, Optional, diff --git a/pymongo/synchronous/settings.py b/pymongo/synchronous/settings.py index 3416bbd130..3008471b25 100644 --- a/pymongo/synchronous/settings.py +++ b/pymongo/synchronous/settings.py @@ -17,8 +17,8 @@ from __future__ import annotations import threading -from collections.abc import Collection -from typing import Callable, Optional +from collections.abc import Callable, Collection +from typing import Optional from bson.objectid import ObjectId from pymongo import common diff --git a/pymongo/synchronous/srv_resolver.py b/pymongo/synchronous/srv_resolver.py index 25fc6f7ad6..3a20043654 100644 --- a/pymongo/synchronous/srv_resolver.py +++ b/pymongo/synchronous/srv_resolver.py @@ -18,7 +18,8 @@ import ipaddress import random -from typing import TYPE_CHECKING, Any, Callable, Optional, Union +from collections.abc import Callable +from typing import TYPE_CHECKING, Any, Optional, Union from pymongo._psl import SPECIAL_USE_LABELS, _to_punycode, is_public_suffix from pymongo._telemetry import log_srv_monitor_invalid_host diff --git a/pymongo/synchronous/topology.py b/pymongo/synchronous/topology.py index 9accc15dc1..e767d9e061 100644 --- a/pymongo/synchronous/topology.py +++ b/pymongo/synchronous/topology.py @@ -24,9 +24,9 @@ import time import warnings import weakref -from collections.abc import Mapping +from collections.abc import Callable, Mapping from pathlib import Path -from typing import TYPE_CHECKING, Any, Callable, Optional, cast +from typing import TYPE_CHECKING, Any, Optional, cast from pymongo import _csot, common, helpers_shared, periodic_executor from pymongo._telemetry import ( diff --git a/pymongo/synchronous/uri_parser.py b/pymongo/synchronous/uri_parser.py index 92608b5efe..9a7fcf0fae 100644 --- a/pymongo/synchronous/uri_parser.py +++ b/pymongo/synchronous/uri_parser.py @@ -17,7 +17,8 @@ from __future__ import annotations -from typing import Any, Callable, Optional +from collections.abc import Callable +from typing import Any, Optional from pymongo.common import SRV_SERVICE_NAME, _CaseInsensitiveDictionary from pymongo.errors import ConfigurationError, InvalidURI diff --git a/pymongo/topology_description.py b/pymongo/topology_description.py index 87966aca45..ab15e7d85a 100644 --- a/pymongo/topology_description.py +++ b/pymongo/topology_description.py @@ -19,11 +19,10 @@ from __future__ import annotations -from collections.abc import Mapping, MutableMapping +from collections.abc import Callable, Mapping, MutableMapping from random import sample from typing import ( Any, - Callable, NamedTuple, Optional, cast, diff --git a/pymongo/topology_shared.py b/pymongo/topology_shared.py index 50bf0c8ad1..23e47557db 100644 --- a/pymongo/topology_shared.py +++ b/pymongo/topology_shared.py @@ -18,8 +18,8 @@ import queue import weakref -from collections.abc import Mapping -from typing import TYPE_CHECKING, Any, Callable, Generic, Optional, TypeVar +from collections.abc import Callable, Mapping +from typing import TYPE_CHECKING, Any, Generic, Optional, TypeVar from pymongo import _csot from pymongo._telemetry import _SdamTelemetry diff --git a/pyproject.toml b/pyproject.toml index a181d9c69d..b4f3e282c2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -243,7 +243,6 @@ ignore = [ "SIM117", # Use a single `with` statement with multiple contexts instead of nested `with` statements "UP045", # Use `X | Y` for union annotation (Enable when we drop 3.9 support) "PLC0415", # `import` should be at the top-level of a file - "UP035", # Deprecated import (e.g. `typing.Callable` instead of `collections.abc.Callable`) "UP041", # `asyncio.TimeoutError` is an alias of `TimeoutError` on 3.11+ "ASYNC109", # Async function with a `timeout` parameter (CSOT timeouts are not `asyncio.timeout`) "UP042", # `str, Enum` should be `StrEnum` (changes `__str__` semantics) diff --git a/test/__init__.py b/test/__init__.py index 00eb1356fb..2220bf3661 100644 --- a/test/__init__.py +++ b/test/__init__.py @@ -43,10 +43,10 @@ HAVE_IPADDRESS = True except ImportError: HAVE_IPADDRESS = False -from collections.abc import Generator +from collections.abc import Callable, Generator from contextlib import contextmanager from functools import partial, wraps -from typing import Any, Callable, overload +from typing import Any, overload from unittest import SkipTest from urllib.parse import quote_plus diff --git a/test/asynchronous/__init__.py b/test/asynchronous/__init__.py index d1eecf41c8..57ee8e9a99 100644 --- a/test/asynchronous/__init__.py +++ b/test/asynchronous/__init__.py @@ -43,10 +43,10 @@ HAVE_IPADDRESS = True except ImportError: HAVE_IPADDRESS = False -from collections.abc import Generator +from collections.abc import Callable, Generator from contextlib import asynccontextmanager, contextmanager from functools import partial, wraps -from typing import Any, Callable, overload +from typing import Any, overload from unittest import SkipTest from urllib.parse import quote_plus diff --git a/test/asynchronous/test_session.py b/test/asynchronous/test_session.py index 5210e25d36..6e3a31d2a7 100644 --- a/test/asynchronous/test_session.py +++ b/test/asynchronous/test_session.py @@ -19,9 +19,10 @@ import copy import sys import time +from collections.abc import Callable from inspect import iscoroutinefunction from io import BytesIO -from typing import Any, Callable +from typing import Any from test.asynchronous.helpers import ExceptionCatchingTask diff --git a/test/test_session.py b/test/test_session.py index 727868e00f..6cd28d27fe 100644 --- a/test/test_session.py +++ b/test/test_session.py @@ -19,9 +19,10 @@ import copy import sys import time +from collections.abc import Callable from inspect import iscoroutinefunction from io import BytesIO -from typing import Any, Callable +from typing import Any from test.helpers import ExceptionCatchingTask diff --git a/test/test_typing.py b/test/test_typing.py index 054466e729..945442d4a9 100644 --- a/test/test_typing.py +++ b/test/test_typing.py @@ -22,18 +22,19 @@ import sys import tempfile import unittest -from collections.abc import Iterable, Iterator +from collections.abc import Callable, Iterable, Iterator from typing import ( TYPE_CHECKING, Any, - Callable, TypeVar, Union, cast, ) if TYPE_CHECKING: - from typing_extensions import NotRequired, TypedDict + from typing import NotRequired + + from typing_extensions import TypedDict from bson import Binary, ObjectId from bson.binary import BinaryVector, BinaryVectorDtype