Repository navigation
Fix more type stub mismatches - #2467
Merged
Merged
Conversation
- Type `SubtitleSet` items as `AssSubtitle | BitmapSubtitle` - Add `BitmapSubtitle` sequence methods, `BitmapSubtitlePlane.__buffer__`, and `VideoFormat.__int__` - Add return types to `CodecContext.encode`, `encode_lazy`, and `decode`; `SubtitleCodecContext.decode` requires a packet - `VideoStream.format` may be `None`, like `VideoCodecContext.format` - Forwarded stream `name` is a `str` - Use `PIL.Image.Image` in `VideoFrame` image methods
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.
More stub fixes, found by type-checking
examples/, comparing each class's runtime dunders against its stub, and comparing stream attributes with the codec-context attributes they forward to.Things that work at runtime but failed type-checking
SubtitleSetitems (rects,__iter__,__getitem__) were typed as the baseSubtitle, but at runtime they are only everAssSubtitleorBitmapSubtitle, sosub.asscould never type-check (examples/subtitles/remux.pyfailed). NowAssSubtitle | BitmapSubtitle, which also lets asub.typecheck narrow the type.BitmapSubtitlehas__len__,__iter__, and__getitem__over its planes at runtime; they're now in the stub.BitmapSubtitlePlanesupports the buffer protocol; added__buffer__, somemoryview(plane)andbytes(plane)type-check.VideoFormathas__int__(used byGraph.add_buffer); added to the stub.Annotation fixes
CodecContext.encode,encode_lazy, anddecodehad no return types.decodereturnsSequence[Frame | AssSubtitle | BitmapSubtitle]; I usedSequencebecauselistis invariant, and thelist[VideoFrame]thatVideoCodecContext.decodereturns wouldn't fit alist[Frame]base.SubtitleCodecContext.decode(None)raisesRuntimeError: packet cannot be None, so its stub now requires aPacket. This uses# type: ignore[override], like the existingencodeoverrides in the audio and video contexts.SubtitleStream.decode(None)still acceptsNone, since it substitutes an empty packet.VideoStream.formatis nowVideoFormat | None, matching theVideoCodecContext.formatit forwards to.name: str, since they forward it to the codec context.VideoFrame.to_imagereturnsPIL.Image.Image, andset_image/from_imagetake one. Pillow is in thetestandlintdependency groups.Notes
stream.format.nameon aVideoStreamnow needs aNonecheck. Four test blocks gainedassert stream.format is not None.examples/subtitles/remux.pynow checksisinstance(sub, AssSubtitle)before usingsub.ass.AudioStream.format/AudioCodecContext.formatcan also beNoneat runtime but are typed as alwaysAudioFormat.