Skip to content

Commit

Permalink
Fix Buffer subclass type definitions
Browse files Browse the repository at this point in the history
It does not make sense to special-case the `Packet` class concerning
buffer protocol support, we have multiple classes inhering our `Buffer`
class:

- `Packet`
- `Plane` and its subclasses `AudioPlane` and `VideoPlane`
- `SideData`

We cannot use `collection.abc.Buffer`, yet as this is only available in
Python 3.12 and up. We do however want to declare that `bytes(foo)` is
available, so declare a `__bytes__` method in `Buffer`.
  • Loading branch information
jlaine committed Jun 21, 2024
1 parent 74fe3fd commit 5c5e31b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 5 additions & 0 deletions av/buffer.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# When Python 3.12 becomes our lowest supported version, we could make this
# class inherit `collections.abc.Buffer`.

class Buffer:
buffer_size: int
buffer_ptr: int
def update(self, input: bytes) -> None: ...
def __buffer__(self, flags: int) -> memoryview: ...
def __bytes__(self) -> bytes: ...
3 changes: 1 addition & 2 deletions av/packet.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from collections.abc import Buffer
from fractions import Fraction

from av.subtitles.subtitle import SubtitleSet

from .buffer import Buffer
from .stream import Stream

class Packet(Buffer):
Expand All @@ -22,4 +22,3 @@ class Packet(Buffer):

def __init__(self, input: int | bytes | None = None) -> None: ...
def decode(self) -> list[SubtitleSet]: ...
def __buffer__(self, arg1) -> memoryview: ...

0 comments on commit 5c5e31b

Please sign in to comment.