Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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