How to use the flynt.format.set_quote_type 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_styles.py View on Github external
def test_initial_doesnt_matter(quote_type):
    code = random.choice(["'abra'", '"bobro"', "'''abra'''", '"""bobro"""'])
    assert get_quote_type(set_quote_type(code, quote_type)) == quote_type
github ikamensh / flynt / test / test_styles.py View on Github external
def test_cycle(code):
    assert set_quote_type(code, get_quote_type(code)) == code
github ikamensh / flynt / test / test_styles.py View on Github external
def test_single():
    code = '"alpha123"'
    expected = "'alpha123'"

    assert set_quote_type(code, QuoteTypes.single) == expected
github ikamensh / flynt / test / test_styles.py View on Github external
def test_single_from_triple():
    code = '"""alpha123"""'
    expected = "'alpha123'"

    assert set_quote_type(code, QuoteTypes.single) == expected
github ikamensh / flynt / src / flynt / transform / transform.py View on Github external
converted, changed, str_in_str = fstringify_node(copy.deepcopy(tree))
    except (SyntaxError, FlyntException, Exception) as e:
        if state.verbose:
            if isinstance(e, ConversionRefused):
                print(f"Not converting code '{code}': {e}")
                print(e)
            else:
                print(f"Exception {e} during conversion of code '{code}'")
                traceback.print_exc()
        state.invalid_conversions += 1
        return code, False
    else:
        if changed:
            new_code = astor.to_source(converted)
            new_code = new_code.strip()
            new_code = set_quote_type(
                new_code, quote_type if not str_in_str else QuoteTypes.double
            )
            new_code = new_code.replace("\n", "\\n")
            new_code = new_code.replace("\t", "\\t")
            try:
                ast.parse(new_code)
            except Exception as e:
                if state.verbose:
                    print(
                        f"Failed to parse transformed code '{new_code}' given original '{code}'"
                    )
                    print(e)
                    traceback.print_exc()
                state.invalid_conversions += 1
                return code, False
            else: