diff --git a/av/packet.py b/av/packet.py index 6b8ea0e60..11a97b5d8 100644 --- a/av/packet.py +++ b/av/packet.py @@ -1,4 +1,5 @@ from collections.abc import Iterator +from types import GenericAlias from typing import Literal, get_args import cython @@ -222,6 +223,12 @@ class Packet(Buffer): :meth:`decode` must be called to extract encoded data. """ + @classmethod + @cython.binding(True) + def __class_getitem__(cls, item): + # Packet is generic over its stream type in the stubs. + return GenericAlias(cls, item) + def __cinit__(self, input=None): with cython.nogil: self.ptr = lib.av_packet_alloc() diff --git a/tests/test_doctests.py b/tests/test_doctests.py index 9b7c78a40..736d27c62 100644 --- a/tests/test_doctests.py +++ b/tests/test_doctests.py @@ -2,7 +2,6 @@ import pkgutil import re import types -from typing import Any from unittest import TestCase import av @@ -11,17 +10,6 @@ VIDEO_PATH = av.datasets.curated("pexels/time-lapse-video-of-night-sky-857195.mp4") -class DocTestFinder(doctest.DocTestFinder): - def find(self, *args: Any, **kwargs: Any) -> list[doctest.DocTest]: - tests = super().find(*args, **kwargs) - for test in tests: - for example in test.examples: - # Remove b prefix from strings. - if example.want.startswith("b'"): - example.want = example.want[1:] - return tests - - def register_doctests(mod: str | types.ModuleType) -> None: if isinstance(mod, str): mod = __import__(mod, fromlist=[""]) @@ -30,7 +18,6 @@ def register_doctests(mod: str | types.ModuleType) -> None: suite = doctest.DocTestSuite( mod, extraglobs={"av": av, "video_path": VIDEO_PATH}, - test_finder=DocTestFinder(), optionflags=doctest.IGNORE_EXCEPTION_DETAIL | doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE, @@ -44,7 +31,7 @@ def register_doctests(mod: str | types.ModuleType) -> None: for test in suite: assert isinstance(test, doctest.DocTestCase) - def func(self: TestCase) -> None: + def func(self: TestCase, test: doctest.DocTestCase = test) -> None: return test.runTest() name = str("test_" + re.sub("[^a-zA-Z0-9]+", "_", test.id()).strip("_"))