harbor run -t openthoughts/tasktrove-exp-rpt-issue-issue-1853harbor download openthoughts/tasktrove-exp-rpt-issue-issue-1853Task: Fix crash when printing an empty Symbol in the pretty printer
Summary: A bug occurs when creating or printing an empty symbol (Symbol('')). The unicode pretty printer ends up calling a function that expects a non-empty name and uses a regex on an undefined/empty string, which raises a TypeError. The fix is to gracefully handle the empty input so Symbol('') can be printed without error.
What you need to do:
Files to create/modify in /app/:
Modify: app/sympy/printing/conventions.py
Create: app/tests/test_symbol_empty_print.py
Notes:
Provided before-state (relevant snippet from conventions.py)
# app/sympy/printing/conventions.py
def split_super_sub(text):
# make a little exception when a name ends with digits, i.e. treat them
# as a subscript too.
m = re.match('(^[a-zA-Z]+)([0-9]+)$', name)
if m is not None:
name, sub = m.groups()
...
What to implement (described behavior, not patch content):
Test to add (example, to place in app/tests/test_symbol_empty_print.py)
# app/tests/test_symbol_empty_print.py
import pytest
from sympy import Symbol
def test_symbol_empty_print_no_exception():
s = Symbol('')
# Should not raise when converting to string
s_str = str(s)
assert isinstance(s_str, str)
# Should also not raise during pretty printing if used
# For a lightweight check, just ensure we can call str() without error
How to run (on your end):
Expected outcome after the fix: