{"record":{"id":"8cbd88e3a857e931","repo":"TheAlgorithms/Python","slug":"axis-must-be-a-str","errorCode":null,"errorMessage":"Axis must be a str","messagePattern":"Axis must be a str","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"graphics/vector3_for_2d_rendering.py","lineNumber":69,"sourceCode":"\n    >>> rotate('1', 2, 3, \"z\", 90.0)  # '1' is str\n    Traceback (most recent call last):\n        ...\n    TypeError: Input values except axis must either be float or int: ['1', 2, 3, 90.0]\n\n    >>> rotate(1, 2, 3, \"n\", 90)  # 'n' is not a valid axis\n    Traceback (most recent call last):\n        ...\n    ValueError: not a valid axis, choose one of 'x', 'y', 'z'\n\n    >>> rotate(1, 2, 3, \"x\", -90)\n    (1, -2.5049096187183877, -2.5933429780983657)\n\n    >>> rotate(1, 2, 3, \"x\", 450)  # 450 wrap around to 90\n    (1, 3.5776792428178217, -0.44744970165427644)\n    \"\"\"\n    if not isinstance(axis, str):\n        raise TypeError(\"Axis must be a str\")\n    input_variables = locals()\n    del input_variables[\"axis\"]\n    if not all(isinstance(val, (float, int)) for val in input_variables.values()):\n        msg = (\n            \"Input values except axis must either be float or int: \"\n            f\"{list(input_variables.values())}\"\n        )\n        raise TypeError(msg)\n    angle = (angle % 360) / 450 * 180 / math.pi\n    if axis == \"z\":\n        new_x = x * math.cos(angle) - y * math.sin(angle)\n        new_y = y * math.cos(angle) + x * math.sin(angle)\n        new_z = z\n    elif axis == \"x\":\n        new_y = y * math.cos(angle) - z * math.sin(angle)\n        new_z = z * math.cos(angle) + y * math.sin(angle)\n        new_x = x\n    elif axis == \"y\":","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/graphics/vector3_for_2d_rendering.py#L51-L87","documentation":"Raised by rotate (graphics/vector3_for_2d_rendering.py:69) when the axis argument is not a str. Axis selects the rotation axis and is validated separately from the numeric arguments because it is the only non-numeric parameter.","triggerScenarios":"rotate(1, 2, 3, 90, 90) — axis/angle swapped positionally; rotate(1, 2, 3, b\"x\", 90); rotate(1, 2, 3, None, 90). Any non-str fourth argument triggers it.","commonSituations":"Argument-order confusion since axis precedes angle in the signature; axis coming from user input or config as bytes or an enum object; passing an int axis index (0/1/2) instead of 'x'/'y'/'z'.","solutions":["Pass the axis as a quoted string: rotate(x, y, z, 'x', 90) or use the keyword rotate(x, y, z, axis='x', angle=90) to avoid order mistakes","Normalize external axis values before calling: axis = str(axis).lower()","Map enum/int codes to 'x'/'y'/'z' at your boundary layer"],"exampleFix":"# before\nnew = rotate(1, 2, 3, 90, 90)  # axis and angle swapped\n\n# after\nnew = rotate(1, 2, 3, axis=\"x\", angle=90)","handlingStrategy":"type-guard","validationCode":"if not isinstance(axis, str):\n    axis = str(axis)\nrotated = rotate(x, y, z, axis=axis, angle=angle)","typeGuard":"def is_axis_str(value: object) -> bool:\n    return isinstance(value, str)","tryCatchPattern":null,"preventionTips":["Call rotate with keyword arguments (axis=..., angle=...) to avoid positional mix-ups","Keep axis values as str from end to end in your pipeline"],"tags":["graphics","type-validation","rotation"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}