Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Replace unconditional typing_extensions imports #3683

Merged
merged 1 commit into from
Nov 15, 2024
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
7 changes: 6 additions & 1 deletion altair/utils/_transformed_data.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Any, overload
from typing_extensions import TypeAlias

from altair import (
Chart,
Expand Down Expand Up @@ -31,8 +30,14 @@
from altair.utils.schemapi import Undefined

if TYPE_CHECKING:
import sys
from collections.abc import Iterable

if sys.version_info >= (3, 10):
from typing import TypeAlias
else:
from typing_extensions import TypeAlias

from altair.typing import ChartType
from altair.utils.core import DataFrameLike

Expand Down
20 changes: 15 additions & 5 deletions altair/utils/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@
Any,
Callable,
Literal,
Protocol,
TypedDict,
TypeVar,
Union,
overload,
runtime_checkable,
)
from typing_extensions import Concatenate, ParamSpec, TypeAlias

import narwhals.stable.v1 as nw
from narwhals.dependencies import is_pandas_dataframe as _is_pandas_dataframe
Expand All @@ -36,11 +33,24 @@
from .plugin_registry import PluginRegistry

if sys.version_info >= (3, 13):
from typing import TypeIs
from typing import Protocol, runtime_checkable
else:
from typing_extensions import TypeIs
from typing_extensions import Protocol, runtime_checkable
if sys.version_info >= (3, 10):
from typing import Concatenate, ParamSpec
else:
from typing_extensions import Concatenate, ParamSpec

if TYPE_CHECKING:
if sys.version_info >= (3, 13):
from typing import TypeIs
else:
from typing_extensions import TypeIs

if sys.version_info >= (3, 10):
from typing import TypeAlias
else:
from typing_extensions import TypeAlias
import pandas as pd
import pyarrow as pa

Expand Down
11 changes: 9 additions & 2 deletions altair/utils/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@
import pkgutil
import textwrap
import uuid
from typing import Any, Callable, Union
from typing_extensions import TypeAlias
from typing import TYPE_CHECKING, Any, Callable, Union

from ._vegafusion_data import compile_with_vegafusion, using_vegafusion
from .mimebundle import spec_to_mimebundle
from .plugin_registry import PluginEnabler, PluginRegistry
from .schemapi import validate_jsonschema

if TYPE_CHECKING:
import sys

if sys.version_info >= (3, 10):
from typing import TypeAlias
else:
from typing_extensions import TypeAlias

# ==============================================================================
# Renderer registry
# ==============================================================================
Expand Down
11 changes: 9 additions & 2 deletions altair/utils/mimebundle.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
from __future__ import annotations

import struct
from typing import Any, Literal, cast, overload
from typing_extensions import TypeAlias
from typing import TYPE_CHECKING, Any, Literal, cast, overload

from ._importers import import_vl_convert, vl_version_for_vl_convert
from .html import spec_to_html

if TYPE_CHECKING:
import sys

if sys.version_info >= (3, 10):
from typing import TypeAlias
else:
from typing_extensions import TypeAlias

MimeBundleFormat: TypeAlias = Literal[
"html", "json", "png", "svg", "pdf", "vega", "vega-lite"
]
Expand Down
13 changes: 11 additions & 2 deletions altair/utils/plugin_registry.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
from __future__ import annotations

import sys
from functools import partial
from importlib.metadata import entry_points
from typing import TYPE_CHECKING, Any, Callable, Generic, cast
from typing_extensions import TypeAliasType, TypeIs, TypeVar
from typing import TYPE_CHECKING, Any, Callable, Generic, TypeVar, cast

from altair.utils.deprecation import deprecated_warn

if sys.version_info >= (3, 13):
from typing import TypeIs
else:
from typing_extensions import TypeIs
if sys.version_info >= (3, 12):
from typing import TypeAliasType
else:
from typing_extensions import TypeAliasType

if TYPE_CHECKING:
from types import TracebackType

Expand Down