From 0ab0c01e2607f0ed122788cae2b3035663656d58 Mon Sep 17 00:00:00 2001 From: WyattBlue Date: Wed, 5 Feb 2025 21:30:00 -0500 Subject: [PATCH] Use new Enum syntax --- av/codec/codec.pyi | 60 +++++++++++------------ av/codec/context.pyi | 70 +++++++++++++-------------- av/codec/hwaccel.pyi | 37 +++++++------- av/container/core.pyi | 102 +++++++++++++++++++-------------------- av/format.pyi | 36 +++++++------- av/option.pyi | 53 ++++++++++---------- av/sidedata/sidedata.pyi | 58 +++++++++++----------- av/stream.pyi | 40 +++++++-------- av/video/frame.pyi | 16 +++--- av/video/reformatter.pyi | 59 +++++++++++----------- 10 files changed, 267 insertions(+), 264 deletions(-) diff --git a/av/codec/codec.pyi b/av/codec/codec.pyi index 3a6c3a866..9f80a4909 100644 --- a/av/codec/codec.pyi +++ b/av/codec/codec.pyi @@ -1,6 +1,6 @@ from enum import Flag, IntEnum from fractions import Fraction -from typing import ClassVar, Literal, overload +from typing import ClassVar, Literal, cast, overload from av.audio.codeccontext import AudioCodecContext from av.audio.format import AudioFormat @@ -12,37 +12,37 @@ from av.video.format import VideoFormat from .context import CodecContext class Properties(Flag): - NONE: ClassVar[Properties] - INTRA_ONLY: ClassVar[Properties] - LOSSY: ClassVar[Properties] - LOSSLESS: ClassVar[Properties] - REORDER: ClassVar[Properties] - BITMAP_SUB: ClassVar[Properties] - TEXT_SUB: ClassVar[Properties] + NONE = cast(ClassVar[Properties], ...) + INTRA_ONLY = cast(ClassVar[Properties], ...) + LOSSY = cast(ClassVar[Properties], ...) + LOSSLESS = cast(ClassVar[Properties], ...) + REORDER = cast(ClassVar[Properties], ...) + BITMAP_SUB = cast(ClassVar[Properties], ...) + TEXT_SUB = cast(ClassVar[Properties], ...) class Capabilities(IntEnum): - none: int - draw_horiz_band: int - dr1: int - hwaccel: int - delay: int - small_last_frame: int - hwaccel_vdpau: int - subframes: int - experimental: int - channel_conf: int - neg_linesizes: int - frame_threads: int - slice_threads: int - param_change: int - auto_threads: int - variable_frame_size: int - avoid_probing: int - hardware: int - hybrid: int - encoder_reordered_opaque: int - encoder_flush: int - encoder_recon_frame: int + none = cast(int, ...) + draw_horiz_band = cast(int, ...) + dr1 = cast(int, ...) + hwaccel = cast(int, ...) + delay = cast(int, ...) + small_last_frame = cast(int, ...) + hwaccel_vdpau = cast(int, ...) + subframes = cast(int, ...) + experimental = cast(int, ...) + channel_conf = cast(int, ...) + neg_linesizes = cast(int, ...) + frame_threads = cast(int, ...) + slice_threads = cast(int, ...) + param_change = cast(int, ...) + auto_threads = cast(int, ...) + variable_frame_size = cast(int, ...) + avoid_probing = cast(int, ...) + hardware = cast(int, ...) + hybrid = cast(int, ...) + encoder_reordered_opaque = cast(int, ...) + encoder_flush = cast(int, ...) + encoder_recon_frame = cast(int, ...) class UnknownCodecError(ValueError): ... diff --git a/av/codec/context.pyi b/av/codec/context.pyi index 543da208e..ac57126ef 100644 --- a/av/codec/context.pyi +++ b/av/codec/context.pyi @@ -1,6 +1,6 @@ from enum import Flag, IntEnum from fractions import Fraction -from typing import ClassVar, Literal +from typing import ClassVar, Literal, cast from av.packet import Packet @@ -8,46 +8,46 @@ from .codec import Codec from .hwaccel import HWAccel class ThreadType(Flag): - NONE: ClassVar[ThreadType] - FRAME: ClassVar[ThreadType] - SLICE: ClassVar[ThreadType] - AUTO: ClassVar[ThreadType] + NONE = cast(ClassVar[ThreadType], ...) + FRAME = cast(ClassVar[ThreadType], ...) + SLICE = cast(ClassVar[ThreadType], ...) + AUTO = cast(ClassVar[ThreadType], ...) def __get__(self, i: object | None, owner: type | None = None) -> ThreadType: ... def __set__(self, instance: object, value: int | str | ThreadType) -> None: ... class Flags(IntEnum): - unaligned: int - qscale: int - four_mv: int - output_corrupt: int - qpel: int - drop_changed: int - recon_frame: int - copy_opaque: int - frame_duration: int - pass1: int - pass2: int - loop_filter: int - gray: int - psnr: int - interlaced_dct: int - low_delay: int - global_header: int - bitexact: int - ac_pred: int - interlaced_me: int - closed_gop: int + unaligned = cast(int, ...) + qscale = cast(int, ...) + four_mv = cast(int, ...) + output_corrupt = cast(int, ...) + qpel = cast(int, ...) + drop_changed = cast(int, ...) + recon_frame = cast(int, ...) + copy_opaque = cast(int, ...) + frame_duration = cast(int, ...) + pass1 = cast(int, ...) + pass2 = cast(int, ...) + loop_filter = cast(int, ...) + gray = cast(int, ...) + psnr = cast(int, ...) + interlaced_dct = cast(int, ...) + low_delay = cast(int, ...) + global_header = cast(int, ...) + bitexact = cast(int, ...) + ac_pred = cast(int, ...) + interlaced_me = cast(int, ...) + closed_gop = cast(int, ...) class Flags2(IntEnum): - fast: int - no_output: int - local_header: int - chunks: int - ignore_crop: int - show_all: int - export_mvs: int - skip_manual: int - ro_flush_noop: int + fast = cast(int, ...) + no_output = cast(int, ...) + local_header = cast(int, ...) + chunks = cast(int, ...) + ignore_crop = cast(int, ...) + show_all = cast(int, ...) + export_mvs = cast(int, ...) + skip_manual = cast(int, ...) + ro_flush_noop = cast(int, ...) class CodecContext: name: str diff --git a/av/codec/hwaccel.pyi b/av/codec/hwaccel.pyi index 84f1da964..8bdc0a6e0 100644 --- a/av/codec/hwaccel.pyi +++ b/av/codec/hwaccel.pyi @@ -1,29 +1,30 @@ from enum import IntEnum +from typing import cast from av.codec.codec import Codec from av.video.format import VideoFormat class HWDeviceType(IntEnum): - none: int - vdpau: int - cuda: int - vaapi: int - dxva2: int - qsv: int - videotoolbox: int - d3d11va: int - drm: int - opencl: int - mediacodec: int - vulkan: int - d3d12va: int + none = cast(int, ...) + vdpau = cast(int, ...) + cuda = cast(int, ...) + vaapi = cast(int, ...) + dxva2 = cast(int, ...) + qsv = cast(int, ...) + videotoolbox = cast(int, ...) + d3d11va = cast(int, ...) + drm = cast(int, ...) + opencl = cast(int, ...) + mediacodec = cast(int, ...) + vulkan = cast(int, ...) + d3d12va = cast(int, ...) class HWConfigMethod(IntEnum): - none: int - hw_device_ctx: int - hw_frame_ctx: int - internal: int - ad_hoc: int + none = cast(int, ...) + hw_device_ctx = cast(int, ...) + hw_frame_ctx = cast(int, ...) + internal = cast(int, ...) + ad_hoc = cast(int, ...) class HWConfig: @property diff --git a/av/container/core.pyi b/av/container/core.pyi index fa996d0d2..d61d07110 100644 --- a/av/container/core.pyi +++ b/av/container/core.pyi @@ -2,7 +2,7 @@ from enum import Flag, IntEnum from fractions import Fraction from pathlib import Path from types import TracebackType -from typing import Any, Callable, ClassVar, Literal, Type, overload +from typing import Any, Callable, ClassVar, Literal, Type, cast, overload from av.codec.hwaccel import HWAccel from av.format import ContainerFormat @@ -14,58 +14,58 @@ from .streams import StreamContainer Real = int | float | Fraction class Flags(Flag): - gen_pts: ClassVar[Flags] - ign_idx: ClassVar[Flags] - non_block: ClassVar[Flags] - ign_dts: ClassVar[Flags] - no_fillin: ClassVar[Flags] - no_parse: ClassVar[Flags] - no_buffer: ClassVar[Flags] - custom_io: ClassVar[Flags] - discard_corrupt: ClassVar[Flags] - flush_packets: ClassVar[Flags] - bitexact: ClassVar[Flags] - sort_dts: ClassVar[Flags] - fast_seek: ClassVar[Flags] - shortest: ClassVar[Flags] - auto_bsf: ClassVar[Flags] + gen_pts = cast(ClassVar[Flags], ...) + ign_idx = cast(ClassVar[Flags], ...) + non_block = cast(ClassVar[Flags], ...) + ign_dts = cast(ClassVar[Flags], ...) + no_fillin = cast(ClassVar[Flags], ...) + no_parse = cast(ClassVar[Flags], ...) + no_buffer = cast(ClassVar[Flags], ...) + custom_io = cast(ClassVar[Flags], ...) + discard_corrupt = cast(ClassVar[Flags], ...) + flush_packets = cast(ClassVar[Flags], ...) + bitexact = cast(ClassVar[Flags], ...) + sort_dts = cast(ClassVar[Flags], ...) + fast_seek = cast(ClassVar[Flags], ...) + shortest = cast(ClassVar[Flags], ...) + auto_bsf = cast(ClassVar[Flags], ...) class AudioCodec(IntEnum): - none: int - pcm_alaw: int - pcm_bluray: int - pcm_dvd: int - pcm_f16le: int - pcm_f24le: int - pcm_f32be: int - pcm_f32le: int - pcm_f64be: int - pcm_f64le: int - pcm_lxf: int - pcm_mulaw: int - pcm_s16be: int - pcm_s16be_planar: int - pcm_s16le: int - pcm_s16le_planar: int - pcm_s24be: int - pcm_s24daud: int - pcm_s24le: int - pcm_s24le_planar: int - pcm_s32be: int - pcm_s32le: int - pcm_s32le_planar: int - pcm_s64be: int - pcm_s64le: int - pcm_s8: int - pcm_s8_planar: int - pcm_u16be: int - pcm_u16le: int - pcm_u24be: int - pcm_u24le: int - pcm_u32be: int - pcm_u32le: int - pcm_u8: int - pcm_vidc: int + none = cast(int, ...) + pcm_alaw = cast(int, ...) + pcm_bluray = cast(int, ...) + pcm_dvd = cast(int, ...) + pcm_f16le = cast(int, ...) + pcm_f24le = cast(int, ...) + pcm_f32be = cast(int, ...) + pcm_f32le = cast(int, ...) + pcm_f64be = cast(int, ...) + pcm_f64le = cast(int, ...) + pcm_lxf = cast(int, ...) + pcm_mulaw = cast(int, ...) + pcm_s16be = cast(int, ...) + pcm_s16be_planar = cast(int, ...) + pcm_s16le = cast(int, ...) + pcm_s16le_planar = cast(int, ...) + pcm_s24be = cast(int, ...) + pcm_s24daud = cast(int, ...) + pcm_s24le = cast(int, ...) + pcm_s24le_planar = cast(int, ...) + pcm_s32be = cast(int, ...) + pcm_s32le = cast(int, ...) + pcm_s32le_planar = cast(int, ...) + pcm_s64be = cast(int, ...) + pcm_s64le = cast(int, ...) + pcm_s8 = cast(int, ...) + pcm_s8_planar = cast(int, ...) + pcm_u16be = cast(int, ...) + pcm_u16le = cast(int, ...) + pcm_u24be = cast(int, ...) + pcm_u24le = cast(int, ...) + pcm_u32be = cast(int, ...) + pcm_u32le = cast(int, ...) + pcm_u8 = cast(int, ...) + pcm_vidc = cast(int, ...) class Container: writeable: bool diff --git a/av/format.pyi b/av/format.pyi index b30a84bf6..81c5c42ca 100644 --- a/av/format.pyi +++ b/av/format.pyi @@ -1,26 +1,26 @@ __all__ = ("Flags", "ContainerFormat", "formats_available") from enum import Flag -from typing import ClassVar, Literal +from typing import ClassVar, Literal, cast class Flags(Flag): - no_file: ClassVar[Flags] - need_number: ClassVar[Flags] - show_ids: ClassVar[Flags] - global_header: ClassVar[Flags] - no_timestamps: ClassVar[Flags] - generic_index: ClassVar[Flags] - ts_discont: ClassVar[Flags] - variable_fps: ClassVar[Flags] - no_dimensions: ClassVar[Flags] - no_streams: ClassVar[Flags] - no_bin_search: ClassVar[Flags] - no_gen_search: ClassVar[Flags] - no_byte_seek: ClassVar[Flags] - allow_flush: ClassVar[Flags] - ts_nonstrict: ClassVar[Flags] - ts_negative: ClassVar[Flags] - seek_to_pts: ClassVar[Flags] + no_file = cast(ClassVar[Flags], ...) + need_number = cast(ClassVar[Flags], ...) + show_ids = cast(ClassVar[Flags], ...) + global_header = cast(ClassVar[Flags], ...) + no_timestamps = cast(ClassVar[Flags], ...) + generic_index = cast(ClassVar[Flags], ...) + ts_discont = cast(ClassVar[Flags], ...) + variable_fps = cast(ClassVar[Flags], ...) + no_dimensions = cast(ClassVar[Flags], ...) + no_streams = cast(ClassVar[Flags], ...) + no_bin_search = cast(ClassVar[Flags], ...) + no_gen_search = cast(ClassVar[Flags], ...) + no_byte_seek = cast(ClassVar[Flags], ...) + allow_flush = cast(ClassVar[Flags], ...) + ts_nonstrict = cast(ClassVar[Flags], ...) + ts_negative = cast(ClassVar[Flags], ...) + seek_to_pts = cast(ClassVar[Flags], ...) class ContainerFormat: def __init__(self, name: str, mode: Literal["r", "w"] | None = None) -> None: ... diff --git a/av/option.pyi b/av/option.pyi index 3132f4a02..f989a1138 100644 --- a/av/option.pyi +++ b/av/option.pyi @@ -1,34 +1,35 @@ from enum import Enum, Flag +from typing import cast class OptionType(Enum): - FLAGS: int - INT: int - INT64: int - DOUBLE: int - FLOAT: int - STRING: int - RATIONAL: int - BINARY: int - DICT: int - CONST: int - IMAGE_SIZE: int - PIXEL_FMT: int - SAMPLE_FMT: int - VIDEO_RATE: int - DURATION: int - COLOR: int - CHANNEL_LAYOUT: int - BOOL: int + FLAGS = cast(int, ...) + INT = cast(int, ...) + INT64 = cast(int, ...) + DOUBLE = cast(int, ...) + FLOAT = cast(int, ...) + STRING = cast(int, ...) + RATIONAL = cast(int, ...) + BINARY = cast(int, ...) + DICT = cast(int, ...) + CONST = cast(int, ...) + IMAGE_SIZE = cast(int, ...) + PIXEL_FMT = cast(int, ...) + SAMPLE_FMT = cast(int, ...) + VIDEO_RATE = cast(int, ...) + DURATION = cast(int, ...) + COLOR = cast(int, ...) + CHANNEL_LAYOUT = cast(int, ...) + BOOL = cast(int, ...) class OptionFlags(Flag): - ENCODING_PARAM: int - DECODING_PARAM: int - AUDIO_PARAM: int - VIDEO_PARAM: int - SUBTITLE_PARAM: int - EXPORT: int - READONLY: int - FILTERING_PARAM: int + ENCODING_PARAM = cast(int, ...) + DECODING_PARAM = cast(int, ...) + AUDIO_PARAM = cast(int, ...) + VIDEO_PARAM = cast(int, ...) + SUBTITLE_PARAM = cast(int, ...) + EXPORT = cast(int, ...) + READONLY = cast(int, ...) + FILTERING_PARAM = cast(int, ...) class BaseOption: name: str diff --git a/av/sidedata/sidedata.pyi b/av/sidedata/sidedata.pyi index d165513ab..0093fabd0 100644 --- a/av/sidedata/sidedata.pyi +++ b/av/sidedata/sidedata.pyi @@ -1,39 +1,39 @@ from collections.abc import Mapping from enum import Enum -from typing import ClassVar, Iterator, Sequence, overload +from typing import ClassVar, Iterator, Sequence, cast, overload from av.buffer import Buffer from av.frame import Frame class Type(Enum): - PANSCAN: ClassVar[Type] - A53_CC: ClassVar[Type] - STEREO3D: ClassVar[Type] - MATRIXENCODING: ClassVar[Type] - DOWNMIX_INFO: ClassVar[Type] - REPLAYGAIN: ClassVar[Type] - DISPLAYMATRIX: ClassVar[Type] - AFD: ClassVar[Type] - MOTION_VECTORS: ClassVar[Type] - SKIP_SAMPLES: ClassVar[Type] - AUDIO_SERVICE_TYPE: ClassVar[Type] - MASTERING_DISPLAY_METADATA: ClassVar[Type] - GOP_TIMECODE: ClassVar[Type] - SPHERICAL: ClassVar[Type] - CONTENT_LIGHT_LEVEL: ClassVar[Type] - ICC_PROFILE: ClassVar[Type] - S12M_TIMECODE: ClassVar[Type] - DYNAMIC_HDR_PLUS: ClassVar[Type] - REGIONS_OF_INTEREST: ClassVar[Type] - VIDEO_ENC_PARAMS: ClassVar[Type] - SEI_UNREGISTERED: ClassVar[Type] - FILM_GRAIN_PARAMS: ClassVar[Type] - DETECTION_BBOXES: ClassVar[Type] - DOVI_RPU_BUFFER: ClassVar[Type] - DOVI_METADATA: ClassVar[Type] - DYNAMIC_HDR_VIVID: ClassVar[Type] - AMBIENT_VIEWING_ENVIRONMENT: ClassVar[Type] - VIDEO_HINT: ClassVar[Type] + PANSCAN = cast(ClassVar[Type], ...) + A53_CC = cast(ClassVar[Type], ...) + STEREO3D = cast(ClassVar[Type], ...) + MATRIXENCODING = cast(ClassVar[Type], ...) + DOWNMIX_INFO = cast(ClassVar[Type], ...) + REPLAYGAIN = cast(ClassVar[Type], ...) + DISPLAYMATRIX = cast(ClassVar[Type], ...) + AFD = cast(ClassVar[Type], ...) + MOTION_VECTORS = cast(ClassVar[Type], ...) + SKIP_SAMPLES = cast(ClassVar[Type], ...) + AUDIO_SERVICE_TYPE = cast(ClassVar[Type], ...) + MASTERING_DISPLAY_METADATA = cast(ClassVar[Type], ...) + GOP_TIMECODE = cast(ClassVar[Type], ...) + SPHERICAL = cast(ClassVar[Type], ...) + CONTENT_LIGHT_LEVEL = cast(ClassVar[Type], ...) + ICC_PROFILE = cast(ClassVar[Type], ...) + S12M_TIMECODE = cast(ClassVar[Type], ...) + DYNAMIC_HDR_PLUS = cast(ClassVar[Type], ...) + REGIONS_OF_INTEREST = cast(ClassVar[Type], ...) + VIDEO_ENC_PARAMS = cast(ClassVar[Type], ...) + SEI_UNREGISTERED = cast(ClassVar[Type], ...) + FILM_GRAIN_PARAMS = cast(ClassVar[Type], ...) + DETECTION_BBOXES = cast(ClassVar[Type], ...) + DOVI_RPU_BUFFER = cast(ClassVar[Type], ...) + DOVI_METADATA = cast(ClassVar[Type], ...) + DYNAMIC_HDR_VIVID = cast(ClassVar[Type], ...) + AMBIENT_VIEWING_ENVIRONMENT = cast(ClassVar[Type], ...) + VIDEO_HINT = cast(ClassVar[Type], ...) class SideData(Buffer): type: Type diff --git a/av/stream.pyi b/av/stream.pyi index a2a2e439c..88dc7c00b 100644 --- a/av/stream.pyi +++ b/av/stream.pyi @@ -1,30 +1,30 @@ from enum import Flag from fractions import Fraction -from typing import Literal +from typing import Literal, cast from .codec import Codec, CodecContext from .container import Container class Disposition(Flag): - default: int - dub: int - original: int - comment: int - lyrics: int - karaoke: int - forced: int - hearing_impaired: int - visual_impaired: int - clean_effects: int - attached_pic: int - timed_thumbnails: int - non_diegetic: int - captions: int - descriptions: int - metadata: int - dependent: int - still_image: int - multilayer: int + default = cast(int, ...) + dub = cast(int, ...) + original = cast(int, ...) + comment = cast(int, ...) + lyrics = cast(int, ...) + karaoke = cast(int, ...) + forced = cast(int, ...) + hearing_impaired = cast(int, ...) + visual_impaired = cast(int, ...) + clean_effects = cast(int, ...) + attached_pic = cast(int, ...) + timed_thumbnails = cast(int, ...) + non_diegetic = cast(int, ...) + captions = cast(int, ...) + descriptions = cast(int, ...) + metadata = cast(int, ...) + dependent = cast(int, ...) + still_image = cast(int, ...) + multilayer = cast(int, ...) class Stream: name: str | None diff --git a/av/video/frame.pyi b/av/video/frame.pyi index 3533c8e3f..d650cf44c 100644 --- a/av/video/frame.pyi +++ b/av/video/frame.pyi @@ -16,14 +16,14 @@ _SupportedNDarray = Union[ ] class PictureType(IntEnum): - NONE: int - I: int - P: int - B: int - S: int - SI: int - SP: int - BI: int + NONE = 0 + I = 1 + P = 2 + B = 3 + S = 4 + SI = 5 + SP = 6 + BI = 7 class VideoFrame(Frame): format: VideoFormat diff --git a/av/video/reformatter.pyi b/av/video/reformatter.pyi index fd5dbd053..5d83fcbe3 100644 --- a/av/video/reformatter.pyi +++ b/av/video/reformatter.pyi @@ -1,41 +1,42 @@ from enum import IntEnum +from typing import cast from .frame import VideoFrame class Interpolation(IntEnum): - FAST_BILINEAER: int - BILINEAR: int - BICUBIC: int - X: int - POINT: int - AREA: int - BICUBLIN: int - GAUSS: int - SINC: int - LANCZOS: int - SPLINE: int + FAST_BILINEAER = cast(int, ...) + BILINEAR = cast(int, ...) + BICUBIC = cast(int, ...) + X = cast(int, ...) + POINT = cast(int, ...) + AREA = cast(int, ...) + BICUBLIN = cast(int, ...) + GAUSS = cast(int, ...) + SINC = cast(int, ...) + LANCZOS = cast(int, ...) + SPLINE = cast(int, ...) class Colorspace(IntEnum): - ITU709: int - FCC: int - ITU601: int - ITU624: int - SMPTE170M: int - SMPTE240M: int - DEFAULT: int - itu709: int - fcc: int - itu601: int - itu624: int - smpte170m: int - smpte240m: int - default: int + ITU709 = cast(int, ...) + FCC = cast(int, ...) + ITU601 = cast(int, ...) + ITU624 = cast(int, ...) + SMPTE170M = cast(int, ...) + SMPTE240M = cast(int, ...) + DEFAULT = cast(int, ...) + itu709 = cast(int, ...) + fcc = cast(int, ...) + itu601 = cast(int, ...) + itu624 = cast(int, ...) + smpte170m = cast(int, ...) + smpte240m = cast(int, ...) + default = cast(int, ...) class ColorRange(IntEnum): - UNSPECIFIED: int - MPEG: int - JPEG: int - NB: int + UNSPECIFIED = 0 + MPEG = 1 + JPEG = 2 + NB = 3 class VideoReformatter: def reformat(