Repository navigation
Fix more type stub contradictions - #2474
Merged
Merged
Conversation
WyattBlue
force-pushed
the
stub-contradictions
branch
from
October 25, 2026 00:59
9fa170f to
51bf16c
Compare
- 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
force-pushed
the
stub-contradictions
branch
from
October 25, 2026 01:04
51bf16c to
b7628ea
Compare
jorenham
reviewed
Oct 26, 2026
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: ... |
Contributor
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Found by checking stub annotations against values on real objects, and with
mypy.stubtest.AudioCodecContext.format/AudioStream.formatareNoneuntil set (e.g. any fresh decoder or encoder), so type themAudioFormat | NonelikeVideoCodecContext.formatAudioResampler.graph: it's a privatecdefattribute, so access raisesAttributeErrorCapture.__exit__receives aTracebackType, not aCallable, and anyBaseExceptionFrame,Plane,Stream, andFilterPadwith@disjoint_base, as stubtest reports