Skip to content

Camera Ready Renderer

Functions:

  • dict_to_params

    Transform a dictionary into a function parameters string.

  • str_to_dict

    Convert a string representation of a dictionary into an actual dictionary.

dict_to_params(arguments)

Transform a dictionary into a function parameters string. Example: {'a': 1, 'b': 2} -> 'a=1, b=2'

Source code in tapeagents/renderers/camera_ready_renderer.py
216
217
218
219
220
221
222
223
def dict_to_params(arguments: str | dict) -> str:
    """
    Transform a dictionary into a function parameters string.
    Example: {'a': 1, 'b': 2} -> 'a=1, b=2'
    """
    if isinstance(arguments, str):
        arguments = str_to_dict(arguments)
    return ", ".join(f"{key}={value!r}" for key, value in arguments.items())

str_to_dict(s)

Convert a string representation of a dictionary into an actual dictionary. Example: "{'a': 1, 'b': 2}" -> {'a': 1, 'b': 2}

Source code in tapeagents/renderers/camera_ready_renderer.py
226
227
228
229
230
231
232
233
234
def str_to_dict(s: str) -> dict:
    """
    Convert a string representation of a dictionary into an actual dictionary.
    Example: "{'a': 1, 'b': 2}" -> {'a': 1, 'b': 2}
    """
    try:
        return ast.literal_eval(s)
    except (ValueError, SyntaxError):
        raise ValueError("Invalid string representation of a dictionary")