From 88f36a5bb67b00a031f8bf7e40a8249460f6e161 Mon Sep 17 00:00:00 2001 From: WyattBlue Date: Tue, 27 Oct 2026 20:09:37 -0400 Subject: [PATCH 1/2] Fix stubtest errors for `__cinit__` constructors --- av/dictionary.pyi | 8 ++++---- av/sidedata/encparams.pyi | 4 ++-- av/sidedata/motionvectors.pyi | 10 +++++----- av/sidedata/sidedata.pyi | 4 ++-- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/av/dictionary.pyi b/av/dictionary.pyi index 818f0b7e1..33e7bc851 100644 --- a/av/dictionary.pyi +++ b/av/dictionary.pyi @@ -1,11 +1,11 @@ from collections.abc import Iterable, Iterator, Mapping -from typing import final +from typing import Self, final @final class Dictionary: - def __init__( - self, *args: Mapping[str, str] | Iterable[tuple[str, str]], **kwargs: str - ) -> None: ... + def __new__( + cls, *args: Mapping[str, str] | Iterable[tuple[str, str]], **kwargs: str + ) -> Self: ... def __getitem__(self, key: str, /) -> str: ... def __setitem__(self, key: str, value: str, /) -> None: ... def __delitem__(self, key: str, /) -> None: ... diff --git a/av/sidedata/encparams.pyi b/av/sidedata/encparams.pyi index d527bcf88..eb9670758 100644 --- a/av/sidedata/encparams.pyi +++ b/av/sidedata/encparams.pyi @@ -1,5 +1,5 @@ from enum import IntEnum -from typing import Any, final +from typing import Any, Self, final import numpy as np @@ -29,4 +29,4 @@ class VideoBlockParams: w: int h: int delta_qp: int - def __init__(self, video_enc_params: VideoEncParams, idx: int, /) -> None: ... + def __new__(cls, video_enc_params: VideoEncParams, idx: int, /) -> Self: ... diff --git a/av/sidedata/motionvectors.pyi b/av/sidedata/motionvectors.pyi index 232910213..d4afa758d 100644 --- a/av/sidedata/motionvectors.pyi +++ b/av/sidedata/motionvectors.pyi @@ -1,5 +1,5 @@ from collections.abc import Iterator -from typing import Any, final +from typing import Any, Self, final import numpy as np @@ -9,7 +9,7 @@ from .sidedata import SideData @final class MotionVectors(SideData): - def __init__(self, sentinel: object, frame: Frame, index: int, /) -> None: ... + def __new__(cls, sentinel: object, frame: Frame, index: int, /) -> Self: ... def __getitem__(self, index: int, /) -> MotionVector: ... def __iter__(self) -> Iterator[MotionVector]: ... def __len__(self) -> int: ... @@ -27,6 +27,6 @@ class MotionVector: motion_x: int motion_y: int motion_scale: int - def __init__( - self, sentinel: object, parent: MotionVectors, index: int, / - ) -> None: ... + def __new__( + cls, sentinel: object, parent: MotionVectors, index: int, / + ) -> Self: ... diff --git a/av/sidedata/sidedata.pyi b/av/sidedata/sidedata.pyi index acde1ebed..269f9cc6e 100644 --- a/av/sidedata/sidedata.pyi +++ b/av/sidedata/sidedata.pyi @@ -1,6 +1,6 @@ from collections.abc import Iterator, Mapping, Sequence from enum import Enum -from typing import Literal, TypeVar, overload +from typing import Literal, Self, TypeVar, overload from typing_extensions import disjoint_base @@ -53,7 +53,7 @@ _VideoEncParamsKey = Literal["VIDEO_ENC_PARAMS", Type.VIDEO_ENC_PARAMS] @disjoint_base class SideData(Buffer): type: Type - def __init__(self, sentinel: object, frame: Frame, index: int, /) -> None: ... + def __new__(cls, sentinel: object, frame: Frame, index: int, /) -> Self: ... class SideDataContainer(Mapping[Type, SideData]): def __len__(self) -> int: ... From 83a97d3a90700c63bd9c0ae247a79319244fc66c Mon Sep 17 00:00:00 2001 From: WyattBlue Date: Tue, 27 Oct 2026 20:13:38 -0400 Subject: [PATCH 2/2] Remove stub-only names that don't exist at runtime --- av/audio/__init__.pyi | 6 ++---- av/codec/codec.pyi | 7 ++----- av/device.pyi | 2 -- av/format.pyi | 2 -- av/packet.pyi | 8 ++++---- av/video/__init__.pyi | 6 ++---- 6 files changed, 10 insertions(+), 21 deletions(-) diff --git a/av/audio/__init__.pyi b/av/audio/__init__.pyi index b6a5c78e0..e50d58532 100644 --- a/av/audio/__init__.pyi +++ b/av/audio/__init__.pyi @@ -1,7 +1,7 @@ from typing import Literal -from .frame import AudioFrame -from .stream import AudioStream +from .frame import AudioFrame as AudioFrame +from .stream import AudioStream as AudioStream # FFmpeg 8.1 encoders and the codec descriptor aliases that resolve to them. _AudioCodecName = Literal[ @@ -118,5 +118,3 @@ _AudioCodecName = Literal[ "wmav1", "wmav2", ] - -__all__ = ("AudioFrame", "AudioStream") diff --git a/av/codec/codec.pyi b/av/codec/codec.pyi index 0a4260c49..830abbee2 100644 --- a/av/codec/codec.pyi +++ b/av/codec/codec.pyi @@ -123,12 +123,9 @@ codecs_available: set[str] def dump_codecs() -> None: ... def dump_hwconfigs() -> None: ... - -PixFmtLike = str | VideoFormat - def find_best_pix_fmt_of_list( - pix_fmts: Sequence[PixFmtLike], - src_pix_fmt: PixFmtLike, + pix_fmts: Sequence[str | VideoFormat], + src_pix_fmt: str | VideoFormat, has_alpha: bool = False, ) -> tuple[VideoFormat | None, PixFmtLoss]: """ diff --git a/av/device.pyi b/av/device.pyi index 33c556994..c336a1f8e 100644 --- a/av/device.pyi +++ b/av/device.pyi @@ -1,5 +1,3 @@ -__all__ = ("DeviceInfo", "enumerate_input_devices", "enumerate_output_devices") - class DeviceInfo: name: str description: str diff --git a/av/format.pyi b/av/format.pyi index c2686a925..e684cbbf1 100644 --- a/av/format.pyi +++ b/av/format.pyi @@ -1,5 +1,3 @@ -__all__ = ("Flags", "ContainerFormat", "formats_available") - from enum import Flag from typing import Literal, Self, final diff --git a/av/packet.pyi b/av/packet.pyi index 4b9847ad6..57351003e 100644 --- a/av/packet.pyi +++ b/av/packet.pyi @@ -81,14 +81,14 @@ def packet_sidedata_type_to_literal(dtype: int) -> PktSideDataT: ... def packet_sidedata_type_from_literal(dtype: PktSideDataT) -> int: ... # TypeVar for stream types - bound to Stream so it can be any stream type -StreamT = TypeVar("StreamT", bound=Stream) +_StreamT = TypeVar("_StreamT", bound=Stream) @final -class Packet(Buffer, Generic[StreamT]): +class Packet(Buffer, Generic[_StreamT]): @property - def stream(self) -> StreamT | None: ... + def stream(self) -> _StreamT | None: ... @stream.setter - def stream(self, value: StreamT) -> None: ... + def stream(self, value: _StreamT) -> None: ... stream_index: int @property def time_base(self) -> AVRational: ... diff --git a/av/video/__init__.pyi b/av/video/__init__.pyi index 63b5e0501..540b181a6 100644 --- a/av/video/__init__.pyi +++ b/av/video/__init__.pyi @@ -1,7 +1,7 @@ from typing import Literal -from .frame import VideoFrame -from .stream import VideoStream +from .frame import VideoFrame as VideoFrame +from .stream import VideoStream as VideoStream # FFmpeg 8.1 encoders and the codec descriptor aliases that resolve to them. _VideoCodecName = Literal[ @@ -193,5 +193,3 @@ _VideoCodecName = Literal[ "zlib", "zmbv", ] - -__all__ = ("VideoFrame", "VideoStream")