{"record":{"id":"e413c2b42e938540","repo":"3b1b/manim","slug":"invalid-selector-sel","errorCode":null,"errorMessage":"Invalid selector: '{sel}'","messagePattern":"Invalid selector: '(.+?)'","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"manimlib/mobject/svg/string_mobject.py","lineNumber":204,"sourceCode":"                isinstance(index, int) or index is None\n                for index in sel\n            ):\n                l = len(self.string)\n                span = tuple(\n                    default_index if index is None else\n                    min(index, l) if index >= 0 else max(index + l, 0)\n                    for index, default_index in zip(sel, (0, l))\n                )\n                return [span]\n            return None\n\n        result = find_spans_by_single_selector(selector)\n        if result is None:\n            result = []\n            for sel in selector:\n                spans = find_spans_by_single_selector(sel)\n                if spans is None:\n                    raise TypeError(f\"Invalid selector: '{sel}'\")\n                result.extend(spans)\n        return list(filter(lambda span: span[0] <= span[1], result))\n\n    @staticmethod\n    def span_contains(span_0: Span, span_1: Span) -> bool:\n        return span_0[0] <= span_1[0] and span_0[1] >= span_1[1]\n\n    # Parsing\n\n    def parse(self) -> None:\n        def get_substr(span: Span) -> str:\n            return self.string[slice(*span)]\n\n        configured_items = self.get_configured_items()\n        isolated_spans = self.find_spans_by_selector(self.isolate)\n        protected_spans = self.find_spans_by_selector(self.protect)\n        command_matches = self.get_command_matches(self.string)\n","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/3b1b/manim/blob/dee01804d47b9f94402d71472674710dcac125b8/manimlib/mobject/svg/string_mobject.py#L186-L222","documentation":"Raised by StringMobject.get_span_indication_parts path (string_mobject.py:204) when a selector in a selector list is of a type the single-selector resolver does not recognize. find_spans_by_single_selector returns None for unsupported types; inside a composite selector list that None triggers this TypeError. Valid single selectors are strings (matched against the string) and (start, end) Span tuples of ints/strings.","triggerScenarios":"Calling mob.get_submobject_from_selector or passing sub_str_to_isolate/substrings_to_isolate with a non-str/non-tuple entry, e.g. ['abc', 3] or [(0.5, 1)] (floats, not ints) inside a composite selector list. A plain string alone does not raise (it may match nothing); the mixed list with an invalid element does.","commonSituations":"Programmatically building selector lists where one element is a number, a regex object, or a span with float indices; assuming regex or index floats are supported like in other APIs.","solutions":["Use only str selectors or (start, end) tuples of int/string endpoints in selector lists","Convert numeric indices with int() before packing them into a span tuple","Validate each selector: isinstance(sel, str) or (isinstance(sel, tuple) and len(sel) == 2 and all(isinstance(i, (int, str)) for i in sel))"],"exampleFix":"# before\nmob.get_submobject_from_selector([\"abc\", (0.5, 1)])  # float span -> raises\n\n# after\nmob.get_submobject_from_selector([\"abc\", (0, 1)])","handlingStrategy":"type-guard","validationCode":"def valid_selector(sel) -> bool:\n    if isinstance(sel, str):\n        return True\n    return (isinstance(sel, tuple) and len(sel) == 2\n            and all(isinstance(i, (int, str)) for i in sel))\n\nselectors = [s for s in selectors if valid_selector(s)]","typeGuard":"def is_valid_selector(sel) -> bool:\n    if isinstance(sel, str):\n        return True\n    return (isinstance(sel, tuple) and len(sel) == 2\n            and all(isinstance(i, (int, str)) for i in sel))","tryCatchPattern":null,"preventionTips":["Use only strings or (start, end) int/string tuples as selectors","Cast float indices with int() before building spans","Validate selector lists in helper functions that assemble them dynamically"],"tags":["manim","selector","string-mobject","type-error","tex"],"backgroundTag":null,"analyzedSha":"dee01804d47b9f94402d71472674710dcac125b8","analyzedAt":"2026-08-14T19:53:44.241Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}