{"record":{"id":"086a7c487467767a","repo":"TheAlgorithms/Python","slug":"the-parameter-s-type-must-be-str","errorCode":null,"errorMessage":"The parameter s type must be str.","messagePattern":"The parameter s type must be str\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"data_compression/burrows_wheeler.py","lineNumber":49,"sourceCode":"    >>> all_rotations(\"^BANANA|\") # doctest: +NORMALIZE_WHITESPACE\n    ['^BANANA|', 'BANANA|^', 'ANANA|^B', 'NANA|^BA', 'ANA|^BAN', 'NA|^BANA',\n    'A|^BANAN', '|^BANANA']\n    >>> all_rotations(\"a_asa_da_casa\") # doctest: +NORMALIZE_WHITESPACE\n    ['a_asa_da_casa', '_asa_da_casaa', 'asa_da_casaa_', 'sa_da_casaa_a',\n    'a_da_casaa_as', '_da_casaa_asa', 'da_casaa_asa_', 'a_casaa_asa_d',\n    '_casaa_asa_da', 'casaa_asa_da_', 'asaa_asa_da_c', 'saa_asa_da_ca',\n    'aa_asa_da_cas']\n    >>> all_rotations(\"panamabanana\") # doctest: +NORMALIZE_WHITESPACE\n    ['panamabanana', 'anamabananap', 'namabananapa', 'amabananapan',\n    'mabananapana', 'abananapanam', 'bananapanama', 'ananapanamab',\n    'nanapanamaba', 'anapanamaban', 'napanamabana', 'apanamabanan']\n    >>> all_rotations(5)\n    Traceback (most recent call last):\n        ...\n    TypeError: The parameter s type must be str.\n    \"\"\"\n    if not isinstance(s, str):\n        raise TypeError(\"The parameter s type must be str.\")\n\n    return [s[i:] + s[:i] for i in range(len(s))]\n\n\ndef bwt_transform(s: str) -> BWTTransformDict:\n    \"\"\"\n    :param s: The string that will be used at bwt algorithm\n    :return: the string composed of the last char of each row of the ordered\n    rotations and the index of the original string at ordered rotations list\n    :raises TypeError: If the s parameter type is not str\n    :raises ValueError: If the s parameter is empty\n    Examples:\n\n    >>> bwt_transform(\"^BANANA\")\n    {'bwt_string': 'BNN^AAA', 'idx_original_string': 6}\n    >>> bwt_transform(\"a_asa_da_casa\")\n    {'bwt_string': 'aaaadss_c__aa', 'idx_original_string': 3}\n    >>> bwt_transform(\"panamabanana\")","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/data_compression/burrows_wheeler.py#L31-L67","documentation":"Raised by all_rotations() in data_compression/burrows_wheeler.py when the input parameter s is not a Python str. The function builds every rotation of a string (s[i:] + s[:i] for each i), which only works on str objects. It validates with isinstance(s, str) before doing any work and rejects everything else, including bytes and lists.","triggerScenarios":"Calling all_rotations(5), all_rotations(['a','b']), all_rotations(b'abc'), or passing a value read from a non-string source (e.g. an int loop counter or a deserialized JSON number) instead of a str.","commonSituations":"Feeding data parsed from JSON or user input where a number slips through, passing bytes from file/network reads without decoding, or test code that passes integers as shown in the doctest all_rotations(5).","solutions":["Convert the value to str before calling: all_rotations(str(value)).","If reading from files/network, decode bytes first: all_rotations(raw.decode('utf-8')).","Add an isinstance check at the call site to fail early with a clearer message for your own layer."],"exampleFix":"# before\nall_rotations(5)  # TypeError\n\n# after\nall_rotations(str(5))  # ['5']","handlingStrategy":"type-guard","validationCode":"if not isinstance(s, str):\n    s = str(s)\nrotations = all_rotations(s)","typeGuard":"def is_str(value: object) -> bool:\n    return isinstance(value, str)","tryCatchPattern":null,"preventionTips":["Decode bytes at the system boundary before passing text around","Keep string-processing pipelines str-typed end to end"],"tags":["type-validation","burrows-wheeler","string","compression"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}