Skip to content

Commit

Permalink
Improve stub for enum, error, logging, stream
Browse files Browse the repository at this point in the history
  • Loading branch information
laggykiller authored Mar 5, 2024
1 parent 1bddc7e commit e4aa4c6
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 24 deletions.
45 changes: 29 additions & 16 deletions av/enum.pyi
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
from typing import Literal, Sequence, overload
from typing import Any, Callable, Iterable, Literal, Sequence, overload

class EnumType(type):
def __init__(self, name, bases, attrs, items): ...
def _create(self, name: str, value: int, doc=None, by_value_only=False): ...
def __len__(self): ...
def __iter__(self): ...
def __getitem__(self, key): ...
def _get(self, value: int, create: bool = False): ...
def _get_multi_flags(self, value: int): ...
def __init__(
self,
name: str,
bases: tuple[type, ...],
attrs: dict[str, Any],
items: Iterable[tuple[str, Any, str | None, bool]],
) -> None: ...
def _create(
self, name: str, value: int, doc: str | None = None, by_value_only: bool = False
) -> None: ...
def __len__(self) -> None: ...
def __iter__(self) -> None: ...
def __getitem__(self, key: str | int | EnumType) -> None: ...
def _get(self, value: int, create: bool = False) -> None: ...
def _get_multi_flags(self, value: int) -> None: ...
def get(
self, key, default: int | None = None, create: bool = False
self,
key: str | int | EnumType,
default: int | None = None,
create: bool = False,
) -> int | None: ...

class EnumItem:
Expand All @@ -18,17 +29,19 @@ class EnumItem:

def __int__(self) -> int: ...
def __hash__(self) -> int: ...
def __reduce__(self): ...
def __eq__(self, other) -> bool: ...
def __ne__(self, other) -> bool: ...
def __reduce__(
self,
) -> tuple[Callable[[str, str, str], EnumItem], tuple[str, str, str]]: ...
def __eq__(self, other: object) -> bool: ...
def __ne__(self, other: object) -> bool: ...

class EnumFlag(EnumItem):
flags: tuple[EnumFlag]

def __and__(self, other): ...
def __or__(self, other): ...
def __xor__(self, other): ...
def __invert__(self): ...
def __and__(self, other: object) -> EnumFlag: ...
def __or__(self, other: object) -> EnumFlag: ...
def __xor__(self, other: object) -> EnumFlag: ...
def __invert__(self) -> bool: ...
def __nonzero__(self) -> bool: ...

@overload
Expand Down
51 changes: 48 additions & 3 deletions av/error.pyi
Original file line number Diff line number Diff line change
@@ -1,13 +1,58 @@
from av.logging import get_last_error
from .enum import EnumItem

classes: dict[int, Exception]

def code_to_tag(code: int) -> bytes: ...
def tag_to_code(tag: bytes) -> int: ...
def make_error(res: int, filename=None, log=None): ...
def make_error(
res: int,
filename: str | None = None,
log: tuple[int, tuple[int, str, str] | None] | None = None,
) -> None: ...

class ErrorType(EnumItem):
BSF_NOT_FOUND: int
BUG: int
BUFFER_TOO_SMALL: int
DECODER_NOT_FOUND: int
DEMUXER_NOT_FOUND: int
ENCODER_NOT_FOUND: int
EOF: int
EXIT: int
EXTERNAL: int
FILTER_NOT_FOUND: int
INVALIDDATA: int
MUXER_NOT_FOUND: int
OPTION_NOT_FOUND: int
PATCHWELCOME: int
PROTOCOL_NOT_FOUND: int
UNKNOWN: int
EXPERIMENTAL: int
INPUT_CHANGED: int
OUTPUT_CHANGED: int
HTTP_BAD_REQUEST: int
HTTP_UNAUTHORIZED: int
HTTP_FORBIDDEN: int
HTTP_NOT_FOUND: int
HTTP_OTHER_4XX: int
HTTP_SERVER_ERROR: int
PYAV_CALLBACK: int

tag: bytes

class FFmpegError(Exception):
def __init__(self, code: int, message, filename=None, log=None): ...
errno: int
strerror: str
filename: str
log: tuple[int, tuple[int, str, str] | None]

def __init__(
self,
code: int,
message: str,
filename: str | None = None,
log: tuple[int, tuple[int, str, str] | None] | None = None,
) -> None: ...

class LookupError(FFmpegError): ...
class HTTPError(FFmpegError): ...
Expand Down
9 changes: 6 additions & 3 deletions av/logging.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
from threading import Lock
from typing import Callable
from typing import Any, Callable

PANIC: int
FATAL: int
Expand Down Expand Up @@ -29,7 +29,10 @@ class Capture:
def __init__(self, local: bool = True) -> None: ...
def __enter__(self) -> list[tuple[int, str, str]]: ...
def __exit__(
self, type_: type | None, value: Exception | None, traceback: Callable | None
self,
type_: type | None,
value: Exception | None,
traceback: Callable[..., Any] | None,
) -> None: ...

level_threshold: int
Expand All @@ -40,4 +43,4 @@ last_log: tuple[int, str, str] | None
skip_count: int
last_error: tuple[int, str, str] | None
global_captures: list[list[tuple[int, str, str]]]
thread_captures: dict
thread_captures: dict[int, list[tuple[int, str, str]]]
14 changes: 12 additions & 2 deletions av/stream.pyi
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
from fractions import Fraction
from typing import Literal

from .codec import CodecContext
from .container import Container
from .enum import EnumItem
from .frame import Frame
from .packet import Packet

class SideData(EnumItem):
DISPLAYMATRIX: int

class Stream:
name: str | None
thread_type: Literal["NONE", "FRAME", "SLICE", "AUTO"]

container: Container
codec_context: CodecContext
metadata: dict[str, str]
id: int
profile: str
nb_side_data: int
side_data: dict[str, str]
index: int
time_base: Fraction | None
Expand All @@ -22,5 +32,5 @@ class Stream:
language: str | None
type: Literal["video", "audio", "data", "subtitle", "attachment"]

def encode(self, frame=None): ...
def decode(self, packet=None): ...
def encode(self, frame: Frame | None = None) -> list[Packet]: ...
def decode(self, packet: Packet | None = None) -> list[Frame]: ...

0 comments on commit e4aa4c6

Please sign in to comment.