How to use the flynt.transform.format_call_transforms.ast_formatted_value function in flynt

To help you get started, we’ve selected a few flynt examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ikamensh / flynt / src / flynt / transform / percent_transformer.py View on Github external
def formatted_value(fmt_prefix, fmt_spec, val):

    if fmt_spec in conversion_methods:
        if not state.aggressive and fmt_prefix:
            raise FlyntException(
                "Default text alignment has changed between percent fmt and fstrings. "
                "Proceeding would result in changed code behaviour."
            )
        fv = ast_formatted_value(
            val, fmt_str=fmt_prefix, conversion=conversion_methods[fmt_spec]
        )
    else:
        fmt_spec = translate_conversion_types.get(fmt_spec, fmt_spec)
        if fmt_spec == "d":
            if state.aggressive:
                val = ast.Call(
                    func=ast.Name(id="int", ctx=ast.Load()), args=[val], keywords={}
                )
                fmt_spec = ""
            else:
                raise FlyntException(
                    "Skipping %d formatting - fstrings behave differently from % formatting."
                )
        fv = ast_formatted_value(val, fmt_str=fmt_prefix + fmt_spec)
    return fv
github ikamensh / flynt / src / flynt / transform / percent_transformer.py View on Github external
fv = ast_formatted_value(
            val, fmt_str=fmt_prefix, conversion=conversion_methods[fmt_spec]
        )
    else:
        fmt_spec = translate_conversion_types.get(fmt_spec, fmt_spec)
        if fmt_spec == "d":
            if state.aggressive:
                val = ast.Call(
                    func=ast.Name(id="int", ctx=ast.Load()), args=[val], keywords={}
                )
                fmt_spec = ""
            else:
                raise FlyntException(
                    "Skipping %d formatting - fstrings behave differently from % formatting."
                )
        fv = ast_formatted_value(val, fmt_str=fmt_prefix + fmt_spec)
    return fv