Recursion-Tree-Visualizer icon indicating copy to clipboard operation
Recursion-Tree-Visualizer copied to clipboard

Escape { to support dictionary in params

Open hishamhijjawi opened this issue 1 year ago • 0 comments

Problem

Right now, if the function which we are visualizing the recursion for has a dictionary or defaultdict in it's param list, I get this error on my mac:

Error: bad label format fib(d={}, n=1)

How to repro:

With the default example provided in the readme, pass in a dictionary to fibonnaci:

# Add decorator
# Decorator accepts optional arguments: ignore_args , show_argument_name, show_return_value and node_properties_kwargs
@vs(node_properties_kwargs={"shape":"record", "color":"#f57542", "style":"filled", "fillcolor":"grey"})
def fib(n,d={}):
    if n <= 1:
        return n
    return fib(n=n - 1, d={}) + fib(n=n - 2, d={'1':'2'})

Solution

If I escape { and }, the error goes away for dictionary and set. For default dict, I also need to escape < and > Not sure if there are any other special chars that need to be escaped because the pydot spec isn't particularly clear, but since dictionary and set both use { and } and those are both used often I figured I'd push this for now. Fix tested locally with the fibonacci example by adding a dictionary filled with arbitrary values to the param list of the fibonacci function.

hishamhijjawi avatar Mar 02 '24 00:03 hishamhijjawi