diff --git a/altair/theme.py b/altair/theme.py index e77a95eb8..54adbd16f 100644 --- a/altair/theme.py +++ b/altair/theme.py @@ -82,7 +82,8 @@ if TYPE_CHECKING: import sys - from typing import Any, Callable, Literal + from collections.abc import Callable + from typing import Any, Literal if sys.version_info >= (3, 11): from typing import LiteralString diff --git a/altair/utils/_vegafusion_data.py b/altair/utils/_vegafusion_data.py index e36fb3455..7fc4ff29d 100644 --- a/altair/utils/_vegafusion_data.py +++ b/altair/utils/_vegafusion_data.py @@ -2,7 +2,7 @@ import uuid from importlib.metadata import version as importlib_version -from typing import TYPE_CHECKING, Any, Callable, Final, TypedDict, Union, overload +from typing import TYPE_CHECKING, Any, Final, TypedDict, Union, overload from weakref import WeakValueDictionary from narwhals.stable.v1.dependencies import is_into_dataframe @@ -20,7 +20,7 @@ if TYPE_CHECKING: import sys - from collections.abc import MutableMapping + from collections.abc import Callable, MutableMapping from narwhals.stable.v1.typing import IntoDataFrame diff --git a/altair/utils/compiler.py b/altair/utils/compiler.py index c8af2d3de..417c8d440 100644 --- a/altair/utils/compiler.py +++ b/altair/utils/compiler.py @@ -1,4 +1,5 @@ -from typing import Any, Callable +from collections.abc import Callable +from typing import Any from altair.utils import PluginRegistry diff --git a/altair/utils/core.py b/altair/utils/core.py index 98daa0d0d..59c845165 100644 --- a/altair/utils/core.py +++ b/altair/utils/core.py @@ -8,11 +8,11 @@ import sys import traceback import warnings -from collections.abc import Iterator, Mapping, MutableMapping +from collections.abc import Callable, Iterator, Mapping, MutableMapping from copy import deepcopy from itertools import groupby from operator import itemgetter -from typing import TYPE_CHECKING, Any, Callable, Literal, TypeVar, cast, overload +from typing import TYPE_CHECKING, Any, Literal, TypeVar, cast, overload import jsonschema import narwhals.stable.v1 as nw @@ -32,8 +32,6 @@ if TYPE_CHECKING: - import typing as t - import pandas as pd from narwhals.stable.v1.typing import IntoExpr @@ -287,7 +285,7 @@ def merge_props_geom(feat: dict[str, Any]) -> dict[str, Any]: return props_geom -def sanitize_geo_interface(geo: t.MutableMapping[Any, Any]) -> dict[str, Any]: +def sanitize_geo_interface(geo: MutableMapping[Any, Any]) -> dict[str, Any]: """ Santize a geo_interface to prepare it for serialization. @@ -768,21 +766,21 @@ def decorate(cb: WrapsFunc[R], /) -> WrappedMethod[T, P, R] | WrappedFunc[P, R]: @overload def update_nested( - original: t.MutableMapping[Any, Any], - update: t.Mapping[Any, Any], + original: MutableMapping[Any, Any], + update: Mapping[Any, Any], copy: Literal[False] = ..., -) -> t.MutableMapping[Any, Any]: ... +) -> MutableMapping[Any, Any]: ... @overload def update_nested( - original: t.Mapping[Any, Any], - update: t.Mapping[Any, Any], + original: Mapping[Any, Any], + update: Mapping[Any, Any], copy: Literal[True], -) -> t.MutableMapping[Any, Any]: ... +) -> MutableMapping[Any, Any]: ... def update_nested( original: Any, - update: t.Mapping[Any, Any], + update: Mapping[Any, Any], copy: bool = False, -) -> t.MutableMapping[Any, Any]: +) -> MutableMapping[Any, Any]: """ Update nested dictionaries. diff --git a/altair/utils/data.py b/altair/utils/data.py index 7964d15a0..565a6df7d 100644 --- a/altair/utils/data.py +++ b/altair/utils/data.py @@ -4,19 +4,10 @@ import json import random import sys -from collections.abc import MutableMapping, Sequence +from collections.abc import Callable, MutableMapping, Sequence from functools import partial from pathlib import Path -from typing import ( - TYPE_CHECKING, - Any, - Callable, - Literal, - TypedDict, - TypeVar, - Union, - overload, -) +from typing import TYPE_CHECKING, Any, Literal, TypedDict, TypeVar, Union, overload import narwhals.stable.v1 as nw from narwhals.stable.v1.dependencies import is_pandas_dataframe diff --git a/altair/utils/display.py b/altair/utils/display.py index 223417a11..475bd3244 100644 --- a/altair/utils/display.py +++ b/altair/utils/display.py @@ -4,7 +4,8 @@ import pkgutil import textwrap import uuid -from typing import TYPE_CHECKING, Any, Callable, Union +from collections.abc import Callable +from typing import TYPE_CHECKING, Any, Union from ._vegafusion_data import compile_with_vegafusion, using_vegafusion from .mimebundle import spec_to_mimebundle diff --git a/altair/utils/execeval.py b/altair/utils/execeval.py index e5e855479..722021ac8 100644 --- a/altair/utils/execeval.py +++ b/altair/utils/execeval.py @@ -2,9 +2,10 @@ import ast import sys -from typing import TYPE_CHECKING, Any, Callable, Literal, overload +from typing import TYPE_CHECKING, Any, Literal, overload if TYPE_CHECKING: + from collections.abc import Callable from os import PathLike from _typeshed import ReadableBuffer diff --git a/altair/utils/plugin_registry.py b/altair/utils/plugin_registry.py index 91e9462eb..f25d9c90a 100644 --- a/altair/utils/plugin_registry.py +++ b/altair/utils/plugin_registry.py @@ -1,9 +1,10 @@ from __future__ import annotations import sys +from collections.abc import Callable from functools import partial from importlib.metadata import entry_points -from typing import TYPE_CHECKING, Any, Callable, Generic, TypeVar, cast +from typing import TYPE_CHECKING, Any, Generic, TypeVar, cast from altair.utils.deprecation import deprecated_warn diff --git a/altair/vegalite/data.py b/altair/vegalite/data.py index cb2d58a59..1e135a9b7 100644 --- a/altair/vegalite/data.py +++ b/altair/vegalite/data.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Callable, overload +from typing import TYPE_CHECKING, overload from altair.utils.core import sanitize_pandas_dataframe from altair.utils.data import DataTransformerRegistry as _DataTransformerRegistry @@ -15,6 +15,8 @@ ) if TYPE_CHECKING: + from collections.abc import Callable + from altair.utils.data import DataType, ToValuesReturnType from altair.utils.plugin_registry import PluginEnabler diff --git a/altair/vegalite/v5/api.py b/altair/vegalite/v5/api.py index 5b3d93f86..c34748fec 100644 --- a/altair/vegalite/v5/api.py +++ b/altair/vegalite/v5/api.py @@ -720,7 +720,7 @@ def _reveal_parsed_shorthand(obj: Map, /) -> dict[str, Any]: def _is_extra(*objs: Any, kwds: Map) -> Iterator[bool]: for el in objs: - if isinstance(el, (SchemaBase, t.Mapping)): + if isinstance(el, (SchemaBase, Mapping)): item = el.to_dict(validate=False) if isinstance(el, SchemaBase) else el yield not (item.keys() - kwds.keys()).isdisjoint(utils.SHORTHAND_KEYS) else: @@ -854,7 +854,7 @@ def _parse_otherwise( conditions.update(**kwds) # type: ignore[call-arg] selection.condition = conditions["condition"] else: - if not isinstance(statement, t.Mapping): + if not isinstance(statement, Mapping): statement = _parse_literal(statement) selection = conditions selection.update(**statement, **kwds) # type: ignore[call-arg] diff --git a/sphinxext/code_ref.py b/sphinxext/code_ref.py index 2eba68a6a..efe9ef5e1 100644 --- a/sphinxext/code_ref.py +++ b/sphinxext/code_ref.py @@ -14,8 +14,8 @@ if TYPE_CHECKING: import sys - from collections.abc import Iterable, Iterator, Mapping, Sequence - from typing import Any, Callable, ClassVar, TypeVar, Union + from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence + from typing import Any, ClassVar, TypeVar, Union from docutils.parsers.rst.states import RSTState, RSTStateMachine from docutils.statemachine import StringList diff --git a/tests/expr/test_expr.py b/tests/expr/test_expr.py index b2200184c..4c662a073 100644 --- a/tests/expr/test_expr.py +++ b/tests/expr/test_expr.py @@ -4,7 +4,7 @@ import operator import sys from inspect import classify_class_attrs, getmembers, signature -from typing import TYPE_CHECKING, Any, Callable, TypeVar, cast +from typing import TYPE_CHECKING, Any, TypeVar, cast import pytest from jsonschema.exceptions import ValidationError @@ -14,7 +14,7 @@ from altair.expr.core import Expression, GetAttrExpression if TYPE_CHECKING: - from collections.abc import Iterable, Iterator + from collections.abc import Callable, Iterable, Iterator from inspect import _IntrospectableCallable T = TypeVar("T") diff --git a/tests/utils/test_data.py b/tests/utils/test_data.py index b4d16d3dd..a365f03dd 100644 --- a/tests/utils/test_data.py +++ b/tests/utils/test_data.py @@ -1,7 +1,7 @@ from __future__ import annotations from pathlib import Path -from typing import Any, Callable, SupportsIndex, TypeVar +from typing import TYPE_CHECKING, Any, SupportsIndex, TypeVar import narwhals.stable.v1 as nw import pandas as pd @@ -17,6 +17,9 @@ to_values, ) +if TYPE_CHECKING: + from collections.abc import Callable + T = TypeVar("T") diff --git a/tests/utils/test_plugin_registry.py b/tests/utils/test_plugin_registry.py index 051d2cdcf..d200bbe96 100644 --- a/tests/utils/test_plugin_registry.py +++ b/tests/utils/test_plugin_registry.py @@ -1,4 +1,4 @@ -from typing import Callable +from collections.abc import Callable from altair.utils.plugin_registry import PluginRegistry diff --git a/tests/utils/test_schemapi.py b/tests/utils/test_schemapi.py index 72d01c0fb..1f847e8dd 100644 --- a/tests/utils/test_schemapi.py +++ b/tests/utils/test_schemapi.py @@ -11,7 +11,7 @@ import warnings from collections import deque from functools import partial -from typing import TYPE_CHECKING, Any, Callable +from typing import TYPE_CHECKING, Any import jsonschema import jsonschema.exceptions @@ -35,7 +35,7 @@ from vega_datasets import data if TYPE_CHECKING: - from collections.abc import Iterable, Sequence + from collections.abc import Callable, Iterable, Sequence from narwhals.stable.v1.typing import IntoDataFrame diff --git a/tests/vegalite/v5/test_theme.py b/tests/vegalite/v5/test_theme.py index 45eda9637..564f8a6ce 100644 --- a/tests/vegalite/v5/test_theme.py +++ b/tests/vegalite/v5/test_theme.py @@ -1,9 +1,9 @@ from __future__ import annotations import json -from collections.abc import Mapping, Set +from collections.abc import Callable, Mapping, Set from pathlib import Path -from typing import TYPE_CHECKING, Any, Callable, Literal, TypeVar, cast, get_args +from typing import TYPE_CHECKING, Any, Literal, TypeVar, cast, get_args import pytest diff --git a/tools/schemapi/codegen.py b/tools/schemapi/codegen.py index dbb3f5974..ad1f4dcb1 100644 --- a/tools/schemapi/codegen.py +++ b/tools/schemapi/codegen.py @@ -5,11 +5,11 @@ import re import sys import textwrap -from collections.abc import Iterable, Iterator +from collections.abc import Callable, Iterable, Iterator from dataclasses import dataclass from itertools import chain, starmap from operator import attrgetter -from typing import Any, Callable, ClassVar, Final, Literal, TypeVar, Union +from typing import Any, ClassVar, Final, Literal, TypeVar, Union from .utils import ( Grouped, diff --git a/tools/update_init_file.py b/tools/update_init_file.py index 5ac9c7cb4..7faa837d3 100644 --- a/tools/update_init_file.py +++ b/tools/update_init_file.py @@ -2,8 +2,10 @@ from __future__ import annotations +import collections.abc as cabc import typing as t import typing_extensions as te +from collections.abc import Sequence from importlib import import_module as _import_module from importlib.util import find_spec as _find_spec from inspect import getattr_static, ismodule @@ -27,10 +29,10 @@ t.Any, t.Literal, t.Union, - t.Iterable, + cabc.Iterable, t.Protocol, te.Protocol, - t.Sequence, + Sequence, t.IO, annotations, te.Required, diff --git a/tools/vega_expr.py b/tools/vega_expr.py index aa42e5ed6..942bcd6da 100644 --- a/tools/vega_expr.py +++ b/tools/vega_expr.py @@ -16,7 +16,7 @@ from itertools import chain from textwrap import TextWrapper as _TextWrapper from textwrap import indent -from typing import TYPE_CHECKING, Any, Callable, ClassVar, Literal, overload +from typing import TYPE_CHECKING, Any, ClassVar, Literal, overload from tools.codemod import ruff from tools.markup import RSTParse, Token, read_ast_tokens @@ -25,7 +25,7 @@ if TYPE_CHECKING: import sys - from collections.abc import Iterable, Iterator, Mapping, Sequence + from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence from pathlib import Path from re import Match, Pattern