Repository navigation
Fix type stub mismatches and HWConfig.methods - #2463
Merged
Merged
Conversation
WyattBlue
force-pushed
the
stub-fixes-2
branch
from
October 24, 2026 04:15
0c988f2 to
d86650f
Compare
- Make `HWConfigMethod` an `IntFlag`, so `HWConfig.methods` no longer raises `ValueError` for combined methods - Return `bool` from `is_encoder`, `is_decoder`, `input_was_opened`, and `is_chroma` - Move video-only rates to `VideoStream`, and context-forwarded `codec`, `codec_tag`, and `options` to audio, video, and subtitle streams - Mark attributes that can be `None` as optional, fix `hardware_configs` and `delay` types, and remove stubs for private fields
WyattBlue
force-pushed
the
stub-fixes-2
branch
from
October 24, 2026 04:21
d86650f to
8992691
Compare
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.
Fixes stub annotations that don't match runtime. I found them by reading every stubbed attribute and property on objects from the test assets and type-checking the real values against the annotations, which catches things stubtest can't see in Cython classes.
Runtime fixes
HWConfig.methodsraisedValueErrorwhenever a config supported several methods (e.g. VideoToolbox h264 reports11), because FFmpeg'smethodsis a bitmask butHWConfigMethodwas anIntEnum. It's now anIntFlag. Addedtest_codec_hardware_config_methods, which fails without the fix.CodecContext.is_encoder,CodecContext.is_decoder,Container.input_was_opened, andVideoFormatComponent.is_chromareturned raw C ints; they now returnbool.Frame.time_basereturnedNonewhen unset; it now returns a falsyAVRational(0, 1), like every otherAVRationalproperty. Internalis Nonechecks inAudioResamplerandGraph.add_buffer/add_abuffernow test truthiness. Code checkingframe.time_base is Noneshould usenot frame.time_base.Stub fixes
average_rate,base_rate, andguessed_ratemoved fromStreamtoVideoStream, the only class that defines them.codec,codec_tag, andoptionsmoved fromStreamtoAudioStream,VideoStream, andSubtitleStream, which forward them to their codec context.DataStreamandAttachmentStreamdon't forward and raiseAttributeError.optionsis nowdict[str, str]there, matchingCodecContext.options: non-strvalues madeopen()raiseTypeError.Stream.codec_contextisCodecContext | None;DataStreamandAttachmentStreamdeclare it asNone.AudioStream.bit_rate,InputContainer.start_time,VideoFrame.time, andFilterPad.context(FilterContextPad.contextstays non-optional).Codec.hardware_configsistuple[HWConfig, ...], notlist;CodecContext.delayisint, notbool.AudioStream.max_bit_rate.Plane.frame,Plane.index, andContainer.buffer_size, which are privatecdeffields.Notes
container.streams[0].codec(a plainStream) no longer type-checks, matching runtime for data streams. Narrow first, e.g.container.streams.video[0]or anisinstancecheck.bit_rate is Nonecontradicted the old stubs. They're now checked, and needed three small edits: twoisinstance(..., av.VideoStream)asserts andstreams.subtitles[0]in place ofstreams[0].add_mux_stream()havecodec_context is None, andAudioStream.format/VideoStream.formatcan beNone, but the stubs say otherwise. Making these optional would forceNonechecks into most stream-handling code, so they're left for a separate decision.