docs(text): document whitespace-stripped indexing in Text#4866
Open
SupernovaIa wants to merge 1 commit into
Open
docs(text): document whitespace-stripped indexing in Text#4866SupernovaIa wants to merge 1 commit into
SupernovaIa wants to merge 1 commit into
Conversation
Text.__init__ strips spaces/newlines from self.text and never creates submobjects for whitespace, so slicing (text[a:b]) and the t2c/t2s/t2w/t2f/t2g '[a:b]' syntax silently index into that stripped copy rather than the original string, with no warning. Add a docstring callout explaining this and pointing to substring-keyed t2c/etc. as the unaffected alternative. Refs ManimCommunity#4864
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.
Summary
Textstrips whitespace/newlines from its internalself.textafter construction, and never creates submobjects for whitespace characters (nothing to render). SinceTextdoesn't override__getitem__, slicing (text[a:b]) and the[a:b]slice syntax int2c/t2s/t2w/t2f/t2gend up indexing into that whitespace-stripped copy — not the string the user actually passed in — with no warning or error.This PR adds a docstring callout on
Textexplaining the behavior and pointing to substring-keyedt2c/etc. (matched by text search, unaffected by this) as the recommended alternative when the target substring is known ahead of time.No behavior changes — docs only.
Fixes #4864
Test plan
uv run pre-commit run --files manim/mobject/text/text_mobject.pypasses (ruff, mypy, codespell)Text(...)still imports/constructs normallyText.__doc__includes the new warning block)