Skip to content

Commit

Permalink
refactor(ruff): Re-run and apply fixes
Browse files Browse the repository at this point in the history
Only required 2 manual fixes

#3497
  • Loading branch information
dangotbanned committed Oct 21, 2024
1 parent c694f65 commit c765897
Show file tree
Hide file tree
Showing 33 changed files with 110 additions and 158 deletions.
4 changes: 2 additions & 2 deletions altair/expr/core.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import Any, Dict, Union
from typing import Any, Union
from typing_extensions import TypeAlias

from altair.utils import SchemaBase
Expand Down Expand Up @@ -237,4 +237,4 @@ def __repr__(self) -> str:
return f"{self.group}[{self.name!r}]"


IntoExpression: TypeAlias = Union[bool, None, str, float, OperatorMixin, Dict[str, Any]]
IntoExpression: TypeAlias = Union[bool, None, str, float, OperatorMixin, dict[str, Any]]
5 changes: 4 additions & 1 deletion altair/utils/_dfi_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
from __future__ import annotations

import enum
from typing import Any, Iterable, Protocol
from typing import TYPE_CHECKING, Any, Protocol

if TYPE_CHECKING:
from collections.abc import Iterable


class DtypeKind(enum.IntEnum):
Expand Down
5 changes: 4 additions & 1 deletion altair/utils/_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import webbrowser
from http.server import BaseHTTPRequestHandler, HTTPServer
from typing import Iterable
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from collections.abc import Iterable


def open_html_in_browser(
Expand Down
8 changes: 5 additions & 3 deletions altair/utils/_transformed_data.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Any, Dict, Iterable, Tuple, overload
from typing import TYPE_CHECKING, Any, overload
from typing_extensions import TypeAlias

from altair import (
Expand Down Expand Up @@ -31,11 +31,13 @@
from altair.utils.schemapi import Undefined

if TYPE_CHECKING:
from collections.abc import Iterable

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

Scope: TypeAlias = Tuple[int, ...]
FacetMapping: TypeAlias = Dict[Tuple[str, Scope], Tuple[str, Scope]]
Scope: TypeAlias = tuple[int, ...]
FacetMapping: TypeAlias = dict[tuple[str, Scope], tuple[str, Scope]]


# For the transformed_data functionality, the chart classes in the values
Expand Down
13 changes: 3 additions & 10 deletions altair/utils/_vegafusion_data.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
from __future__ import annotations

import uuid
from typing import (
TYPE_CHECKING,
Any,
Callable,
Final,
MutableMapping,
TypedDict,
Union,
overload,
)
from typing import TYPE_CHECKING, Any, Callable, Final, TypedDict, Union, overload
from weakref import WeakValueDictionary

from altair.utils._importers import import_vegafusion
Expand All @@ -24,6 +15,8 @@
from altair.vegalite.data import default_data_transformer

if TYPE_CHECKING:
from collections.abc import MutableMapping

from narwhals.typing import IntoDataFrame

from vegafusion.runtime import ChartState
Expand Down
6 changes: 3 additions & 3 deletions altair/utils/compiler.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from typing import Any, Callable, Dict
from typing import Any, Callable

from altair.utils import PluginRegistry

# ==============================================================================
# Vega-Lite to Vega compiler registry
# ==============================================================================
VegaLiteCompilerType = Callable[[Dict[str, Any]], Dict[str, Any]]
VegaLiteCompilerType = Callable[[dict[str, Any]], dict[str, Any]]


class VegaLiteCompilerRegistry(PluginRegistry[VegaLiteCompilerType, Dict[str, Any]]):
class VegaLiteCompilerRegistry(PluginRegistry[VegaLiteCompilerType, dict[str, Any]]):
pass
13 changes: 2 additions & 11 deletions altair/utils/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,11 @@
import sys
import traceback
import warnings
from collections.abc import Mapping, MutableMapping
from collections.abc import Iterator, Mapping, MutableMapping
from copy import deepcopy
from itertools import groupby
from operator import itemgetter
from typing import (
TYPE_CHECKING,
Any,
Callable,
Iterator,
Literal,
TypeVar,
cast,
overload,
)
from typing import TYPE_CHECKING, Any, Callable, Literal, TypeVar, cast, overload

import jsonschema
import narwhals.stable.v1 as nw
Expand Down
15 changes: 6 additions & 9 deletions altair/utils/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@
import json
import random
import sys
from collections.abc import MutableMapping, Sequence
from functools import partial
from pathlib import Path
from typing import (
TYPE_CHECKING,
Any,
Callable,
Dict,
List,
Literal,
MutableMapping,
Protocol,
Sequence,
TypedDict,
TypeVar,
Union,
Expand Down Expand Up @@ -54,17 +51,17 @@ class SupportsGeoInterface(Protocol):


DataType: TypeAlias = Union[
Dict[Any, Any], IntoDataFrame, SupportsGeoInterface, DataFrameLike
dict[Any, Any], IntoDataFrame, SupportsGeoInterface, DataFrameLike
]

TDataType = TypeVar("TDataType", bound=DataType)
TIntoDataFrame = TypeVar("TIntoDataFrame", bound=IntoDataFrame)

VegaLiteDataDict: TypeAlias = Dict[
str, Union[str, Dict[Any, Any], List[Dict[Any, Any]]]
VegaLiteDataDict: TypeAlias = dict[
str, Union[str, dict[Any, Any], list[dict[Any, Any]]]
]
ToValuesReturnType: TypeAlias = Dict[str, Union[Dict[Any, Any], List[Dict[Any, Any]]]]
SampleReturnType = Union[IntoDataFrame, Dict[str, Sequence], None]
ToValuesReturnType: TypeAlias = dict[str, Union[dict[Any, Any], list[dict[Any, Any]]]]
SampleReturnType = Union[IntoDataFrame, dict[str, Sequence], None]


def is_data_type(obj: Any) -> TypeIs[DataType]:
Expand Down
12 changes: 6 additions & 6 deletions altair/utils/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pkgutil
import textwrap
import uuid
from typing import Any, Callable, Dict, Tuple, Union
from typing import Any, Callable, Union
from typing_extensions import TypeAlias

from ._vegafusion_data import compile_with_vegafusion, using_vegafusion
Expand All @@ -18,16 +18,16 @@
# MimeBundleType needs to be the same as what are acceptable return values
# for _repr_mimebundle_,
# see https://ipython.readthedocs.io/en/stable/config/integrating.html#MyObject._repr_mimebundle_
MimeBundleDataType: TypeAlias = Dict[str, Any]
MimeBundleMetaDataType: TypeAlias = Dict[str, Any]
MimeBundleDataType: TypeAlias = dict[str, Any]
MimeBundleMetaDataType: TypeAlias = dict[str, Any]
MimeBundleType: TypeAlias = Union[
MimeBundleDataType, Tuple[MimeBundleDataType, MimeBundleMetaDataType]
MimeBundleDataType, tuple[MimeBundleDataType, MimeBundleMetaDataType]
]
RendererType: TypeAlias = Callable[..., MimeBundleType]
# Subtype of MimeBundleType as more specific in the values of the dictionaries

DefaultRendererReturnType: TypeAlias = Tuple[
Dict[str, Union[str, Dict[str, Any]]], Dict[str, Dict[str, Any]]
DefaultRendererReturnType: TypeAlias = tuple[
dict[str, Union[str, dict[str, Any]]], dict[str, dict[str, Any]]
]


Expand Down
13 changes: 4 additions & 9 deletions altair/utils/schemapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,17 @@
import sys
import textwrap
from collections import defaultdict
from collections.abc import Iterable, Iterator, Mapping, Sequence
from functools import partial
from importlib.metadata import version as importlib_version
from itertools import chain, zip_longest
from math import ceil
from typing import (
TYPE_CHECKING,
Any,
Dict,
Final,
Generic,
Iterable,
Iterator,
List,
Literal,
Mapping,
Sequence,
TypeVar,
Union,
cast,
Expand Down Expand Up @@ -67,8 +62,8 @@
from typing_extensions import Never, Self
_OptionalModule: TypeAlias = "ModuleType | None"

ValidationErrorList: TypeAlias = List[jsonschema.exceptions.ValidationError]
GroupedValidationErrors: TypeAlias = Dict[str, ValidationErrorList]
ValidationErrorList: TypeAlias = list[jsonschema.exceptions.ValidationError]
GroupedValidationErrors: TypeAlias = dict[str, ValidationErrorList]

# This URI is arbitrary and could be anything else. It just cannot be an empty
# string as we need to reference the schema registered in
Expand Down Expand Up @@ -1351,7 +1346,7 @@ def _replace_parsed_shorthand(

TSchemaBase = TypeVar("TSchemaBase", bound=SchemaBase)

_CopyImpl = TypeVar("_CopyImpl", SchemaBase, Dict[Any, Any], List[Any])
_CopyImpl = TypeVar("_CopyImpl", SchemaBase, dict[Any, Any], list[Any])
"""
Types which have an implementation in ``SchemaBase.copy()``.
Expand Down
4 changes: 2 additions & 2 deletions altair/utils/selection.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from __future__ import annotations

from dataclasses import dataclass
from typing import Any, Dict, List, NewType
from typing import Any, NewType

# Type representing the "{selection}_store" dataset that corresponds to a
# Vega-Lite selection
Store = NewType("Store", List[Dict[str, Any]])
Store = NewType("Store", list[dict[str, Any]])


@dataclass(frozen=True, eq=True)
Expand Down
7 changes: 4 additions & 3 deletions altair/vegalite/v5/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import typing as t
import warnings
from copy import deepcopy as _deepcopy
from typing import TYPE_CHECKING, Any, Literal, Sequence, TypeVar, Union, overload
from typing import TYPE_CHECKING, Any, Literal, TypeVar, Union, overload

import jsonschema
import narwhals.stable.v1 as nw
Expand Down Expand Up @@ -47,8 +47,9 @@
from typing_extensions import TypeAlias

if TYPE_CHECKING:
from collections.abc import Iterable, Iterator, Sequence
from pathlib import Path
from typing import IO, Iterable, Iterator
from typing import IO

from altair.utils.core import DataFrameLike

Expand Down Expand Up @@ -661,7 +662,7 @@ class _ConditionClosed(TypedDict, closed=True, total=False): # type: ignore[cal
value: Any


_Conditions: TypeAlias = t.List[_ConditionClosed]
_Conditions: TypeAlias = list[_ConditionClosed]
"""
Chainable conditions produced by ``.when()`` and ``Then.when()``.
Expand Down
4 changes: 3 additions & 1 deletion altair/vegalite/v5/schema/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from __future__ import annotations

import sys
from typing import TYPE_CHECKING, Any, Literal, Sequence, TypedDict
from typing import TYPE_CHECKING, Any, Literal, TypedDict

if sys.version_info >= (3, 14):
from typing import TypedDict
Expand All @@ -14,6 +14,8 @@

if TYPE_CHECKING:
# ruff: noqa: F405
from collections.abc import Sequence

from ._typing import * # noqa: F403


Expand Down
8 changes: 2 additions & 6 deletions altair/vegalite/v5/schema/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

import re
import sys
from typing import Any, Generic, Literal, Mapping, Sequence, TypeVar, Union
from collections.abc import Mapping, Sequence
from typing import Annotated, Any, Generic, Literal, TypeVar, Union, get_args

if sys.version_info >= (3, 14): # https://peps.python.org/pep-0728/
from typing import TypedDict
Expand All @@ -32,11 +33,6 @@
else:
from typing_extensions import TypeAlias

if sys.version_info >= (3, 9):
from typing import Annotated, get_args
else:
from typing_extensions import Annotated, get_args


__all__ = [
"AggregateOp_T",
Expand Down
4 changes: 3 additions & 1 deletion altair/vegalite/v5/schema/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# However, we need these overloads due to how the propertysetter works
# mypy: disable-error-code="no-overload-impl, empty-body, misc"
import sys
from typing import TYPE_CHECKING, Any, Literal, Sequence, TypedDict, Union, overload
from typing import TYPE_CHECKING, Any, Literal, TypedDict, Union, overload

if sys.version_info >= (3, 10):
from typing import TypeAlias
Expand All @@ -28,6 +28,8 @@

if TYPE_CHECKING:
# ruff: noqa: F405
from collections.abc import Sequence

from altair import Parameter, SchemaBase
from altair.typing import Optional
from altair.vegalite.v5.api import IntoCondition
Expand Down
4 changes: 3 additions & 1 deletion altair/vegalite/v5/schema/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import json
import pkgutil
from typing import TYPE_CHECKING, Any, Iterator, Literal, Sequence
from typing import TYPE_CHECKING, Any, Literal

from altair.utils.schemapi import ( # noqa: F401
SchemaBase,
Expand All @@ -16,6 +16,8 @@

if TYPE_CHECKING:
# ruff: noqa: F405
from collections.abc import Iterator, Sequence

from altair import Parameter
from altair.typing import Optional

Expand Down
5 changes: 3 additions & 2 deletions altair/vegalite/v5/schema/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

from __future__ import annotations

from typing import TYPE_CHECKING, Literal, Sequence
from typing import TYPE_CHECKING, Literal

from altair.utils import Undefined, use_signature

from . import core

if TYPE_CHECKING:
from altair import Parameter, SchemaBase
from collections.abc import Sequence

if TYPE_CHECKING:
# ruff: noqa: F405
Expand All @@ -20,6 +20,7 @@
from typing import Self
else:
from typing_extensions import Self
from altair import Parameter, SchemaBase
from altair.typing import Optional

from ._typing import * # noqa: F403
Expand Down
Loading

0 comments on commit c765897

Please sign in to comment.