From 829caedf5fdd2234a3c58aec67d7823be111a026 Mon Sep 17 00:00:00 2001 From: WyattBlue Date: Wed, 17 Apr 2024 15:50:14 -0400 Subject: [PATCH] Fix type hint for packet, is_annexb --- av/packet.pyi | 4 +++- tests/test_bitstream.py | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/av/packet.pyi b/av/packet.pyi index 91775eff7..14b4b0bce 100644 --- a/av/packet.pyi +++ b/av/packet.pyi @@ -1,5 +1,6 @@ +from collections.abc import Buffer from fractions import Fraction -from typing import Buffer, Iterator +from typing import Iterator from av.subtitles.subtitle import SubtitleSet @@ -22,3 +23,4 @@ class Packet(Buffer): def __init__(self, input: int | bytes | None = None) -> None: ... def decode(self) -> Iterator[SubtitleSet]: ... + def __buffer__(self, arg1) -> memoryview: ... diff --git a/tests/test_bitstream.py b/tests/test_bitstream.py index 937448fe5..8538594a7 100644 --- a/tests/test_bitstream.py +++ b/tests/test_bitstream.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import av from av import Packet from av.bitstream import BitStreamFilterContext, bitstream_filters_available @@ -5,7 +7,10 @@ from .common import TestCase, fate_suite -def is_annexb(packet: Packet) -> bool: +def is_annexb(packet: Packet | bytes | None) -> bool: + if packet is None: + return False + data = bytes(packet) return data[:3] == b"\0\0\x01" or data[:4] == b"\0\0\0\x01"