Skip to content

Commit

Permalink
Fix typing
Browse files Browse the repository at this point in the history
  • Loading branch information
Setsugennoao committed Oct 6, 2022
1 parent 993f9dc commit b7e27ac
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 25 deletions.
9 changes: 4 additions & 5 deletions vsexprtools/exprop.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from __future__ import annotations

from enum import Enum
from itertools import cycle
from math import isqrt
from typing import Any, Iterable, Iterator, List, SupportsFloat
from typing import Any, Iterable, Iterator, SupportsFloat

from vstools import ConvMode, StrList, flatten
from vstools import ConvMode, CustomStrEnum, StrList, flatten

from .util import aka_expr_available

Expand All @@ -14,7 +13,7 @@
]


class ExprOp(str, Enum):
class ExprOp(CustomStrEnum):
# 1 Argument
EXP = "exp"
LOG = "log"
Expand Down Expand Up @@ -78,7 +77,7 @@ def __next__(self) -> ExprOp:
def __iter__(self) -> Iterator[ExprOp]:
return cycle([self])

def __mul__(self, n: int) -> List[ExprOp]: # type: ignore[override]
def __mul__(self, n: int) -> list[ExprOp]: # type: ignore[override]
return [self] * n

@classmethod
Expand Down
13 changes: 7 additions & 6 deletions vsexprtools/funcs.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from __future__ import annotations

from math import ceil
from typing import Any, Iterable, List, Literal, Sequence, Tuple
from typing import Any, Iterable, Literal, Sequence


from vstools import PlanesT, StrArr, StrArrOpt, StrList, SupportsString, VideoFormatT, get_video_format, to_arr
from vstools import (
EXPR_VARS, PlanesT, StrArr, StrArrOpt, StrList, SupportsString, VideoFormatT, core, get_video_format, to_arr, vs
)

from .exprop import ExprOp
from .util import EXPR_VARS, aka_expr_available, norm_expr_planes
from .util import aka_expr_available, norm_expr_planes

__all__ = [
'expr_func', 'combine', 'norm_expr'
Expand Down Expand Up @@ -47,7 +48,7 @@ def expr_func(
) from e


def _combine_norm__ix(ffix: StrArrOpt, n_clips: int) -> List[SupportsString]:
def _combine_norm__ix(ffix: StrArrOpt, n_clips: int) -> list[SupportsString]:
if ffix is None:
return [''] * n_clips

Expand All @@ -74,7 +75,7 @@ def combine(


def norm_expr(
clips: vs.VideoNode | Iterable[vs.VideoNode], expr: str | StrArr | Tuple[str | StrArr, ...],
clips: vs.VideoNode | Iterable[vs.VideoNode], expr: str | StrArr | tuple[str | StrArr, ...],
planes: PlanesT = None, format: VideoFormatT | None = None, opt: bool | None = None,
boundary: bool = False, force_akarin: Literal[False] | str = False, **kwargs: Any
) -> vs.VideoNode:
Expand Down
10 changes: 5 additions & 5 deletions vsexprtools/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import builtins
from contextlib import AbstractContextManager
from types import TracebackType
from typing import List, NamedTuple, Sequence, Type
from typing import NamedTuple, Sequence

from vstools import EXPR_VARS, vs

from .funcs import expr_func
from .operators import ExprOperators
from .polyfills import global_builtins, global_builtins_expr
from .util import EXPR_VARS
from .variables import ClipVar, ComputedVar, ExprVar

__all__ = [
Expand All @@ -18,13 +18,13 @@


class InlineExpr(NamedTuple):
clips: List[ClipVar]
clips: list[ClipVar]
op: ExprOperators
out: inline_expr


class inline_expr(AbstractContextManager[InlineExpr]):
_clips: List[vs.VideoNode]
_clips: list[vs.VideoNode]
_in_context: bool
_final_clip: vs.VideoNode | None
_final_expr_node: ComputedVar
Expand All @@ -48,7 +48,7 @@ def __enter__(self) -> InlineExpr:
return InlineExpr(self._clips_char_map, ExprOperators(), self)

def __exit__(
self, __exc_type: Type[BaseException] | None,
self, __exc_type: type[BaseException] | None,
__exc_value: BaseException | None,
__traceback: TracebackType | None
) -> bool | None:
Expand Down
10 changes: 5 additions & 5 deletions vsexprtools/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import operator as op
from dataclasses import dataclass
from typing import (
TYPE_CHECKING, Any, Callable, Generic, Iterable, List, Sequence, SupportsAbs, SupportsIndex, SupportsRound,
TypeAlias, Union, cast, overload
TYPE_CHECKING, Any, Callable, Generic, Iterable, Sequence, SupportsAbs, SupportsIndex, SupportsRound, TypeAlias,
Union, cast, overload
)

from vstools import R, SupportsFloatOrIndex, SupportsRichComparison, SupportsTrunc, T
Expand Down Expand Up @@ -228,12 +228,12 @@ def as_var(cls, arg0: ExprOtherT) -> ComputedVar:

@overload
@classmethod
def as_var(cls, arg0: Sequence[ExprOtherT]) -> List[ComputedVar]:
def as_var(cls, arg0: Sequence[ExprOtherT]) -> list[ComputedVar]:
pass

@classmethod
def as_var(cls, arg0: ExprOtherT | Sequence[ExprOtherT]) -> ComputedVar | List[ComputedVar]:
def as_var(cls, arg0: ExprOtherT | Sequence[ExprOtherT]) -> ComputedVar | list[ComputedVar]:
from .variables import ComputedVar
if isinstance(arg0, Sequence):
return cast(List[ComputedVar], list(arg0))
return cast(list[ComputedVar], list(arg0))
return cast(ComputedVar, arg0)
7 changes: 3 additions & 4 deletions vsexprtools/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
from dataclasses import dataclass
from functools import wraps
from typing import (
TYPE_CHECKING, Any, Callable, Iterable, Iterator, Literal, NoReturn, SupportsIndex, Tuple, TypeAlias, cast, overload
TYPE_CHECKING, Any, Callable, Iterable, Iterator, Literal, NoReturn, SupportsIndex, TypeAlias, cast, overload
)


from vstools import (
ByteData, ColorRange, ColorRangeT, F, Self, get_depth, get_lowest_value, get_neutral_value, get_peak_value,
get_plane_sizes, scale_value
get_plane_sizes, scale_value, vs
)

from .operators import BaseOperator, ExprOperators
Expand Down Expand Up @@ -290,7 +289,7 @@ def __str__(self) -> str:
# Pixel Access
_IdxType: TypeAlias = int | ExprVar

def __getitem__(self, index: _IdxType | Tuple[_IdxType, _IdxType] | slice) -> ComputedVar: # type: ignore
def __getitem__(self, index: _IdxType | tuple[_IdxType, _IdxType] | slice) -> ComputedVar: # type: ignore
if isinstance(index, tuple):
x, y = index
if isinstance(x, ExprVar) or isinstance(y, ExprVar):
Expand Down

0 comments on commit b7e27ac

Please sign in to comment.