Skip to content

Fix more type stub contradictions - #2474

Merged
WyattBlue merged 1 commit into
masterfrom
stub-contradictions
Oct 25, 2026
Merged

WyattBlue merged 1 commit into
masterfrom
stub-contradictions

Conversation

@WyattBlue

Copy link
Copy Markdown
Member

Found by checking stub annotations against values on real objects, and with mypy.stubtest.

  • AudioCodecContext.format / AudioStream.format are None until set (e.g. any fresh decoder or encoder), so type them AudioFormat | None like VideoCodecContext.format
  • Remove AudioResampler.graph: it's a private cdef attribute, so access raises AttributeError
  • Capture.__exit__ receives a TracebackType, not a Callable, and any BaseException
  • Mark Frame, Plane, Stream, and FilterPad with @disjoint_base, as stubtest reports

@WyattBlue
WyattBlue force-pushed the stub-contradictions branch from 9fa170f to 51bf16c Compare October 25, 2026 00:59
- Audio codec context and stream `format` may be `None`, like video
- Remove `AudioResampler.graph`, which isn't exposed at runtime
- Type `Capture.__exit__` with `BaseException` and `TracebackType`
- Mark `Frame`, `Plane`, `Stream`, and `FilterPad` with `@disjoint_base`
@WyattBlue
WyattBlue force-pushed the stub-contradictions branch from 51bf16c to b7628ea Compare October 25, 2026 01:04
@WyattBlue
WyattBlue merged commit 50a3f0d into master Oct 25, 2026
9 checks passed
@WyattBlue
WyattBlue deleted the stub-contradictions branch October 25, 2026 01:09
Comment thread av/audio/codeccontext.pyi
Comment on lines +18 to +25
@property
def format(self) -> AudioFormat | None: ...
@format.setter
def format(self, value: AudioFormat | str) -> None: ...
@property
def layout(self) -> AudioLayout: ...
@layout.setter
def layout(self, value: AudioLayout | str) -> None: ...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, stubtest doesn't seem to like this:

av.audio.stream.AudioStream.format is not present at runtime
av.audio.stream.AudioStream.layout is not present at runtime

A workaround could be to write this as

Suggested change
@property
def format(self) -> AudioFormat | None: ...
@format.setter
def format(self, value: AudioFormat | str) -> None: ...
@property
def layout(self) -> AudioLayout: ...
@layout.setter
def layout(self, value: AudioLayout | str) -> None: ...
format: AudioFormat | Any | None
layout: AudioLayout | Any

which loses some type-safety, but still allows setting them with str.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants