How to use the flynt.process.fstringify_concats 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 / test / test_process.py View on Github external
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
github ikamensh / flynt / test / test_process.py View on Github external
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
github ikamensh / flynt / src / flynt / api.py View on Github external
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: