Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_concat_two_sides():
s_in = """t = 'T is a string of value: ' + val + ' and thats great!'"""
s_expected = """t = f"T is a string of value: {val} and thats great!\""""
s_out, count = process.fstringify_concats(s_in)
assert s_out == s_expected
def test_concat():
s_in = """msg = a + " World\""""
s_expected = """msg = f"{a} World\""""
s_out, count = process.fstringify_concats(s_in)
assert s_out == s_expected
def default_result():
return False, 0, len(contents), len(contents)
try:
ast_before = ast.parse(contents)
except SyntaxError:
if not state.quiet:
print(f"Can't parse {filename} as a python file.")
return default_result()
try:
new_code, changes = fstringify_code_by_line(
contents, multiline=multiline, len_limit=len_limit
)
if transform_concat:
new_code, concat_changes = fstringify_concats(
new_code, multiline=multiline, len_limit=len_limit
)
changes += concat_changes
state.concat_changes += concat_changes
except Exception as e:
if not state.quiet:
print(f"Skipping fstrings transform of file {filename} due to {e}")
if state.verbose:
traceback.print_exc()
return default_result()
if new_code == contents:
return default_result()
try: