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
7 changes: 7 additions & 0 deletions av/packet.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from collections.abc import Iterator
from types import GenericAlias
from typing import Literal, get_args

import cython
Expand Down Expand Up @@ -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()
Expand Down
15 changes: 1 addition & 14 deletions tests/test_doctests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import pkgutil
import re
import types
from typing import Any
from unittest import TestCase

import av
Expand All @@ -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=[""])
Expand All @@ -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,
Expand All @@ -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("_"))
Expand Down