Skip to content

Commit

Permalink
Add slots=True
Browse files Browse the repository at this point in the history
  • Loading branch information
WyattBlue committed Aug 21, 2023
1 parent 43a927d commit 9bf25d6
Show file tree
Hide file tree
Showing 20 changed files with 46 additions and 43 deletions.
2 changes: 1 addition & 1 deletion auto_editor/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
}


@dataclass
@dataclass(slots=True)
class FileSetup:
src: FileInfo
ensure: Ensure
Expand Down
6 changes: 3 additions & 3 deletions auto_editor/ffwrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def pipe(self, cmd: list[str]) -> str:
return output


@dataclass
@dataclass(slots=True)
class VideoStream:
width: int
height: int
Expand All @@ -149,7 +149,7 @@ class VideoStream:
lang: str | None


@dataclass
@dataclass(slots=True)
class AudioStream:
codec: str
samplerate: int
Expand All @@ -159,7 +159,7 @@ class AudioStream:
lang: str | None


@dataclass
@dataclass(slots=True)
class SubtitleStream:
codec: str
ext: str
Expand Down
7 changes: 4 additions & 3 deletions auto_editor/lang/palet.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@
from auto_editor.utils.func import boolop, mut_margin

if TYPE_CHECKING:
from typing import Any, Callable, NoReturn, Union
from collections.abc import Callable
from typing import Any, NoReturn

from numpy.typing import NDArray

Number = Union[int, float, complex, Fraction]
Real = Union[int, float, Fraction]
Number = int | float | complex | Fraction
Real = int | float | Fraction
BoolList = NDArray[np.bool_]


Expand Down
3 changes: 2 additions & 1 deletion auto_editor/lib/contracts.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import annotations

from collections.abc import Callable
from fractions import Fraction
from typing import Any, Callable
from typing import Any

from .data_structs import Sym, print_str
from .err import MyError
Expand Down
13 changes: 6 additions & 7 deletions auto_editor/output.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import os.path
from dataclasses import dataclass
from fractions import Fraction

from auto_editor.ffwrapper import FFmpeg, FileInfo
Expand All @@ -9,14 +10,12 @@
from auto_editor.utils.types import Args


@dataclass(slots=True)
class Ensure:
__slots__ = ("_ffmpeg", "_sr", "temp", "log")

def __init__(self, ffmpeg: FFmpeg, sr: int, temp: str, log: Log):
self._ffmpeg = ffmpeg
self._sr = sr
self.temp = temp
self.log = log
_ffmpeg: FFmpeg
_sr: int
temp: str
log: Log

def audio(self, path: str, label: str, stream: int) -> str:
out_path = os.path.join(self.temp, f"{label}-{stream}.wav")
Expand Down
4 changes: 1 addition & 3 deletions auto_editor/render/image.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from __future__ import annotations

from typing import Union

import av
from PIL import Image, ImageChops, ImageDraw, ImageFont, ImageOps

Expand All @@ -27,7 +25,7 @@ def apply_anchor(x: int, y: int, w: int, h: int, anchor: str) -> tuple[int, int]
return x, y


FontCache = dict[tuple[str, int], Union[ImageFont.FreeTypeFont, ImageFont.ImageFont]]
FontCache = dict[tuple[str, int], ImageFont.FreeTypeFont | ImageFont.ImageFont]
ImgCache = dict[str, Image.Image]


Expand Down
2 changes: 1 addition & 1 deletion auto_editor/render/subtitle.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from auto_editor.utils.log import Log


@dataclass
@dataclass(slots=True)
class SerialSub:
start: int
end: int
Expand Down
2 changes: 1 addition & 1 deletion auto_editor/render/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
av.logging.set_level(av.logging.PANIC)


@dataclass
@dataclass(slots=True)
class VideoFrame:
index: int
src: str
Expand Down
2 changes: 1 addition & 1 deletion auto_editor/subcommands/desc.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from auto_editor.vanparse import ArgumentParser


@dataclass
@dataclass(slots=True)
class DescArgs:
ffmpeg_location: str | None = None
help: bool = False
Expand Down
2 changes: 1 addition & 1 deletion auto_editor/subcommands/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from auto_editor.vanparse import ArgumentParser


@dataclass
@dataclass(slots=True)
class InfoArgs:
json: bool = False
ffmpeg_location: str | None = None
Expand Down
2 changes: 1 addition & 1 deletion auto_editor/subcommands/levels.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from numpy.typing import NDArray


@dataclass
@dataclass(slots=True)
class LevelArgs:
input: list[str] = field(default_factory=list)
edit: str = "audio"
Expand Down
2 changes: 1 addition & 1 deletion auto_editor/subcommands/repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
pass


@dataclass
@dataclass(slots=True)
class REPL_Args:
input: list[str] = field(default_factory=list)
debug_parser: bool = False
Expand Down
2 changes: 1 addition & 1 deletion auto_editor/subcommands/subdump.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from auto_editor.vanparse import ArgumentParser


@dataclass
@dataclass(slots=True)
class SubArgs:
ffmpeg_location: str | None = None
my_ffmpeg: bool = False
Expand Down
5 changes: 3 additions & 2 deletions auto_editor/subcommands/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
import shutil
import subprocess
import sys
from collections.abc import Callable
from dataclasses import dataclass, field
from fractions import Fraction
from time import perf_counter
from typing import Any, Callable
from typing import Any

import numpy as np

Expand All @@ -20,7 +21,7 @@
from auto_editor.vanparse import ArgumentParser


@dataclass
@dataclass(slots=True)
class TestArgs:
only: list[str] = field(default_factory=list)
help: bool = False
Expand Down
8 changes: 4 additions & 4 deletions auto_editor/timeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from dataclasses import dataclass
from fractions import Fraction
from typing import Any, Union
from typing import Any

from auto_editor.ffwrapper import FileInfo
from auto_editor.lib.contracts import *
Expand All @@ -11,7 +11,7 @@
from auto_editor.utils.types import Align


@dataclass
@dataclass(slots=True)
class v1:
"""
v1 timeline constructor
Expand Down Expand Up @@ -177,8 +177,8 @@ class TlEllipse(_Visual):
"audio": (TlAudio, audio_builder),
}

Visual = Union[TlText, TlImage, TlRect, TlEllipse]
VLayer = list[Union[TlVideo, Visual]]
Visual = TlText | TlImage | TlRect | TlEllipse
VLayer = list[TlVideo | Visual]
VSpace = list[VLayer]

ALayer = list[TlAudio]
Expand Down
2 changes: 1 addition & 1 deletion auto_editor/utils/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class DictContainer(TypedDict, total=False):
samplerate: list[int] | None


@dataclass
@dataclass(slots=True)
class Container:
name: str | None = None
allow_video: bool = False
Expand Down
2 changes: 1 addition & 1 deletion auto_editor/utils/func.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

from collections.abc import Callable
from fractions import Fraction
from typing import Callable

import numpy as np
from numpy.typing import NDArray
Expand Down
4 changes: 2 additions & 2 deletions auto_editor/utils/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import re
from dataclasses import dataclass, field
from fractions import Fraction
from typing import Literal, Union
from typing import Literal


class CoerceError(Exception):
Expand Down Expand Up @@ -196,7 +196,7 @@ def align(val: str) -> Align:
raise CoerceError("Align must be 'left', 'right', or 'center'")


Stream = Union[int, Literal["all"]]
Stream = int | Literal["all"]


def stream(val: str) -> Stream:
Expand Down
15 changes: 9 additions & 6 deletions auto_editor/vanparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@
from dataclasses import dataclass
from io import StringIO
from shutil import get_terminal_size
from typing import Any, Callable, Literal, TypeVar, Union
from typing import TYPE_CHECKING

from auto_editor.utils.log import Log
from auto_editor.utils.types import CoerceError

T = TypeVar("T")
Nargs = Union[int, Literal["*"]]
if TYPE_CHECKING:
from typing import Any, Callable, Literal, TypeVar

T = TypeVar("T")
Nargs = int | Literal["*"]

@dataclass

@dataclass(slots=True)
class Required:
names: tuple[str, ...]
nargs: Nargs = "*"
Expand All @@ -26,7 +29,7 @@ class Required:
metavar: str = "[file ...] [options]"


@dataclass
@dataclass(slots=True)
class Options:
names: tuple[str, ...]
nargs: Nargs = 1
Expand All @@ -37,7 +40,7 @@ class Options:
help: str = ""


@dataclass
@dataclass(slots=True)
class OptionText:
text: str

Expand Down
4 changes: 2 additions & 2 deletions auto_editor/wavfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
import io
import struct
import sys
from typing import Literal, Union
from typing import Literal

import numpy as np

PCM = 0x0001
IEEE_FLOAT = 0x0003
EXTENSIBLE = 0xFFFE

AudioData = Union[np.memmap, np.ndarray]
AudioData = np.memmap | np.ndarray
Endian = Literal[">", "<"] # Big Endian, Little Endian
ByteOrd = Literal["big", "little"]

Expand Down

0 comments on commit 9bf25d6

Please sign in to comment.