<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def canonicalize_half_turns( half_turns: Union[sympy.Basic, float] ) -> Union[sympy.Basic, float]: """Wraps the input into the range (-1, +1]."""

    if isinstance(half_turns, sympy.Basic):
        return half_turns
    half_turns %= 2
    if half_turns > 1:
        half_turns -= 2
    return half_turns