Skip to content

Commit cb65007

Browse files
committed
Match more type stubs to the runtime
VideoStream.__getattr__ raises AttributeError for framerate and rate on purpose, so the stub let code type-check that failed at runtime. Drop them, along with Buffer.__bytes__ and InputContainer.flush_buffers(), which do not exist from Python either. HWAccel defaults allow_software_fallback to True, not False, and accepts an int device type. ArgumentError is also a ValueError. Add HWAccel.config, FilterContext.filter, Subtitle.type, and VideoCodecContext.reformatter, which the runtime has and the stubs did not.
1 parent c511c21 commit cb65007

8 files changed

Lines changed: 10 additions & 15 deletions

File tree

‎av/buffer.pyi‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@ class Buffer:
66
buffer_ptr: int
77
def update(self, input: bytes) -> None: ...
88
def __buffer__(self, flags: int) -> memoryview: ...
9-
def __bytes__(self) -> bytes: ...

‎av/codec/hwaccel.pyi‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,17 @@ class HWAccel:
5656
options: dict[str, object]
5757
flags: int
5858
allow_software_fallback: bool
59+
config: HWConfig | None
5960

6061
@property
6162
def is_hw_owned(self) -> bool: ...
6263
@property
6364
def device_id(self) -> int: ...
6465
def __init__(
6566
self,
66-
device_type: str | HWDeviceType,
67+
device_type: str | int | HWDeviceType,
6768
device: str | int | None = None,
68-
allow_software_fallback: bool = False,
69+
allow_software_fallback: bool = True,
6970
options: dict[str, object] | None = None,
7071
flags: int | None = None,
7172
is_hw_owned: bool = False,

‎av/container/input.pyi‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,3 @@ class InputContainer(Container):
8787
unsupported_frame_offset: bool = False,
8888
unsupported_byte_offset: bool = False,
8989
) -> None: ...
90-
def flush_buffers(self) -> None: ...

‎av/error.pyi‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,4 @@ class OSError(FFmpegError, builtins.OSError): ...
7070
class PermissionError(FFmpegError, builtins.PermissionError): ...
7171
class ProcessLookupError(FFmpegError, builtins.ProcessLookupError): ...
7272
class TimeoutError(FFmpegError, builtins.TimeoutError): ...
73-
class ArgumentError(FFmpegError): ...
73+
class ArgumentError(FFmpegError, builtins.ValueError): ...

‎av/filter/context.pyi‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
from av.filter import Graph
2+
from av.filter.filter import Filter
23
from av.filter.link import FilterContextPad
34
from av.frame import Frame
45

56
class FilterContext:
67
name: str | None
8+
filter: Filter
79

810
@property
911
def inputs(self) -> tuple[FilterContextPad, ...]: ...

‎av/subtitles/subtitle.pyi‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ class SubtitleSet:
2020
def __iter__(self) -> Iterator[Subtitle]: ...
2121
def __getitem__(self, i: int) -> Subtitle: ...
2222

23-
class Subtitle: ...
23+
class Subtitle:
24+
type: bytes
2425

2526
class BitmapSubtitle(Subtitle):
2627
type: Literal[b"bitmap"]

‎av/video/codeccontext.pyi‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ from av.rational import AVRational
88

99
from .format import VideoFormat
1010
from .frame import VideoFrame
11+
from .reformatter import VideoReformatter
1112

1213
class VideoCodecContext(CodecContext):
1314
format: VideoFormat | None
1415
width: int
1516
height: int
1617
bits_per_coded_sample: int
1718
pix_fmt: str | None
19+
reformatter: VideoReformatter | None
1820
@property
1921
def sw_format(self) -> VideoFormat | None: ...
2022
@sw_format.setter

‎av/video/stream.pyi‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from collections.abc import Iterator, Sequence
2-
from fractions import Fraction
32
from typing import Literal
43

54
from av.codec.context import ThreadType
@@ -35,14 +34,6 @@ class VideoStream(Stream):
3534
height: int
3635
bits_per_coded_sample: int
3736
pix_fmt: str | None
38-
@property
39-
def framerate(self) -> AVRational: ...
40-
@framerate.setter
41-
def framerate(self, value: AVRational | Fraction | int) -> None: ...
42-
@property
43-
def rate(self) -> AVRational: ...
44-
@rate.setter
45-
def rate(self, value: AVRational | Fraction | int) -> None: ...
4637
gop_size: int
4738
has_b_frames: bool
4839
max_b_frames: int

0 commit comments

Comments
 (0)