Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions av/audio/codeccontext.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,20 @@ from .format import AudioFormat
from .frame import AudioFrame
from .layout import AudioLayout

class _Format:
def __get__(self, i: object | None, owner: type | None = None) -> AudioFormat: ...
def __set__(self, instance: object, value: AudioFormat | str) -> None: ...

class _Layout:
def __get__(self, i: object | None, owner: type | None = None) -> AudioLayout: ...
def __set__(self, instance: object, value: AudioLayout | str) -> None: ...

@final
class AudioCodecContext(CodecContext):
frame_size: int
sample_rate: int
rate: int
type: Literal["audio"]
format: _Format
layout: _Layout
@property
def format(self) -> AudioFormat | None: ...
@format.setter
def format(self, value: AudioFormat | str) -> None: ...
@property
def layout(self) -> AudioLayout: ...
@layout.setter
def layout(self, value: AudioLayout | str) -> None: ...
Comment on lines +18 to +25

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, stubtest doesn't seem to like this:

av.audio.stream.AudioStream.format is not present at runtime
av.audio.stream.AudioStream.layout is not present at runtime

A workaround could be to write this as

Suggested change
@property
def format(self) -> AudioFormat | None: ...
@format.setter
def format(self, value: AudioFormat | str) -> None: ...
@property
def layout(self) -> AudioLayout: ...
@layout.setter
def layout(self, value: AudioLayout | str) -> None: ...
format: AudioFormat | Any | None
layout: AudioLayout | Any

which loses some type-safety, but still allows setting them with str.

@property
def channels(self) -> int: ...
@property
Expand Down
15 changes: 4 additions & 11 deletions av/audio/frame.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,16 @@ _SupportedNDarray = (
| np.ndarray[Any, np.dtype[np.uint8]] # u1
)

class _Format:
def __get__(self, i: object | None, owner: type | None = None) -> AudioFormat: ...
def __set__(self, instance: object, value: AudioFormat | str) -> None: ...

class _Layout:
def __get__(self, i: object | None, owner: type | None = None) -> AudioLayout: ...
def __set__(self, instance: object, value: AudioLayout | str) -> None: ...

@final
class AudioFrame(Frame):
planes: tuple[AudioPlane, ...]
samples: int
sample_rate: int
rate: int
format: _Format
layout: _Layout

@property
def format(self) -> AudioFormat: ...
@property
def layout(self) -> AudioLayout: ...
def __init__(
self,
format: AudioFormat | str = "s16",
Expand Down
3 changes: 0 additions & 3 deletions av/audio/resampler.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from typing import final

from av.filter.graph import Graph

from .format import AudioFormat
from .frame import AudioFrame
from .layout import AudioLayout
Expand All @@ -14,7 +12,6 @@ class AudioResampler:
format: AudioFormat
layout: AudioLayout
options: dict[str, str]
graph: Graph | None
is_passthrough: bool

def __init__(
Expand Down
18 changes: 8 additions & 10 deletions av/audio/stream.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@ from .format import AudioFormat
from .frame import AudioFrame
from .layout import AudioLayout

class _Format:
def __get__(self, i: object | None, owner: type | None = None) -> AudioFormat: ...
def __set__(self, instance: object, value: AudioFormat | str) -> None: ...

class _Layout:
def __get__(self, i: object | None, owner: type | None = None) -> AudioLayout: ...
def __set__(self, instance: object, value: AudioLayout | str) -> None: ...

@final
class AudioStream(Stream):
codec_context: AudioCodecContext
Expand All @@ -39,5 +31,11 @@ class AudioStream(Stream):
rate: int
channels: int
type: Literal["audio"]
format: _Format
layout: _Layout
@property
def format(self) -> AudioFormat | None: ...
@format.setter
def format(self, value: AudioFormat | str) -> None: ...
@property
def layout(self) -> AudioLayout: ...
@layout.setter
def layout(self, value: AudioLayout | str) -> None: ...
3 changes: 3 additions & 0 deletions av/filter/link.pyi
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from typing import final

from typing_extensions import disjoint_base

from av.filter.context import FilterContext
from av.filter.filter import Filter
from av.filter.graph import Graph

@disjoint_base
class FilterPad:
filter: Filter
context: FilterContext | None
Expand Down
3 changes: 3 additions & 0 deletions av/frame.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from fractions import Fraction

from typing_extensions import disjoint_base

from av.rational import AVRational
from av.sidedata.sidedata import SideDataContainer

@disjoint_base
class Frame:
dts: int | None
pts: int | None
Expand Down
10 changes: 5 additions & 5 deletions av/logging.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from collections.abc import Callable
from typing import Any, final
from types import TracebackType
from typing import final

PANIC: int
FATAL: int
Expand Down Expand Up @@ -29,7 +29,7 @@ class Capture:
def __enter__(self) -> list[tuple[int, str, str]]: ...
def __exit__(
self,
type_: type | None,
value: Exception | None,
traceback: Callable[..., Any] | None,
type_: type[BaseException] | None,
value: BaseException | None,
traceback: TracebackType | None,
) -> None: ...
3 changes: 3 additions & 0 deletions av/plane.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from typing_extensions import disjoint_base

from .buffer import Buffer
from .frame import Frame

@disjoint_base
class Plane(Buffer):
def __init__(self, frame: Frame, index: int) -> None: ...
3 changes: 3 additions & 0 deletions av/stream.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ from enum import IntEnum, IntFlag
from fractions import Fraction
from typing import Literal, final

from typing_extensions import disjoint_base

from av.rational import AVRational

from .codec import CodecContext
Expand Down Expand Up @@ -38,6 +40,7 @@ class Discard(IntEnum):
nonkey = ...
all = ...

@disjoint_base
class Stream:
name: str | None
container: Container
Expand Down
2 changes: 2 additions & 0 deletions tests/test_encode.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ def test_default_options(self) -> None:
assert not stream.time_base

# codec context properties
assert stream.format is not None
assert stream.format.name == "s16"
assert stream.sample_rate == 48000

Expand Down Expand Up @@ -243,6 +244,7 @@ def test_transcode(self) -> None:
stream = container.streams[0]

# codec context properties
assert stream.format is not None
assert stream.format.name == "s16p"
assert stream.sample_rate == sample_rate

Expand Down
1 change: 1 addition & 0 deletions tests/test_file_probing.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def test_stream_probing(self) -> None:
assert stream.channels == 2
assert stream.codec.name == "aac_latm"
assert stream.codec.long_name == "AAC LATM (Advanced Audio Coding LATM syntax)"
assert stream.format is not None
assert stream.format.bits == 32
assert stream.format.name == "fltp"
assert stream.layout.name == "stereo"
Expand Down
1 change: 1 addition & 0 deletions tests/test_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import av
import av.datasets
import av.filter.loudnorm

from .common import fate_suite

Expand Down
1 change: 1 addition & 0 deletions tests/test_videoframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import pytest

import av
import av.filter
from av import VideoFrame
from av.video.frame import supported_np_pix_fmts
from av.video.reformatter import Colorspace, Interpolation
Expand Down
Loading