How to use the flynt.format.QuoteTypes.double 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
        ('"bobro"', QuoteTypes.double),
        ("'''abra'''", QuoteTypes.triple_single),
        ('"""bobro"""', QuoteTypes.triple_double),
    ],
)
def test_get_quote_type(code, quote_type):
    assert get_quote_type(code) == quote_type
github ikamensh / flynt / src / flynt / string_concat / transformer.py View on Github external
def transform_concat(code: str, *args, **kwargs) -> Tuple[str, bool]:
    tree = ast.parse(f"({code})")

    ft = ConcatTransformer()
    ft.visit(tree)
    il = FstrInliner()
    il.visit(tree)

    new_code = astor.to_source(tree)
    if new_code[-1] == "\n":
        new_code = new_code[:-1]

    new_code = new_code.replace("\n", "\\n")
    if new_code[:4] == 'f"""':
        new_code = set_quote_type(new_code, QuoteTypes.double)

    return new_code, ft.counter > 0
github ikamensh / flynt / src / flynt / process.py View on Github external
def try_chunk(self, chunk):

        for line in self.src_lines[chunk.start_line : chunk.start_line + chunk.n_lines]:
            if noqa_regex.findall(line):
                # user does not wish for this line to be converted.
                return

        try:
            if chunk.string_in_string:
                quote_type = qt.double
            else:
                quote_type = chunk.quote_type

        except FlyntException as e:
            if state.verbose:
                print(f"Exception {e} during conversion of code '{str(chunk)}'")
                traceback.print_exc()

        else:
            converted, changed = self.transform_func(str(chunk), quote_type=quote_type)
            if changed:
                contract_lines = chunk.n_lines - 1
                if contract_lines == 0:
                    line = self.src_lines[chunk.start_line]
                    rest = line[chunk.end_idx:]
                else:
github ikamensh / flynt / src / flynt / transform / transform.py View on Github external
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:
                return new_code, changed