Skip to content

docs(text): document whitespace-stripped indexing in Text#4866

Open
SupernovaIa wants to merge 1 commit into
ManimCommunity:mainfrom
SupernovaIa:docs/text-index-whitespace-caveat
Open

docs(text): document whitespace-stripped indexing in Text#4866
SupernovaIa wants to merge 1 commit into
ManimCommunity:mainfrom
SupernovaIa:docs/text-index-whitespace-caveat

Conversation

@SupernovaIa

Copy link
Copy Markdown

Summary

Text strips whitespace/newlines from its internal self.text after construction, and never creates submobjects for whitespace characters (nothing to render). Since Text doesn't override __getitem__, slicing (text[a:b]) and the [a:b] slice syntax in t2c/t2s/t2w/t2f/t2g end 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 Text explaining the behavior and pointing to substring-keyed t2c/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.py passes (ruff, mypy, codespell)
  • Text(...) still imports/constructs normally
  • Docstring renders as expected (Text.__doc__ includes the new warning block)

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
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.

Text slicing/indexing silently operates on a whitespace-stripped copy of the string, not the original

1 participant