Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
('"""bobro"""', QuoteTypes.triple_double),
],
)
def test_get_quote_type_token(code, quote_type):
g = get_chunks(code)
next(g)
chunk = next(g)
token = chunk.tokens[0]
assert token.get_quote_type() == quote_type
def maybe_replace(self, chunk, contract_lines, converted, rest):
if contract_lines:
if get_quote_type(str(chunk)) in (qt.triple_double, qt.triple_single):
lines = converted.split("\\n")
lines[-1] += rest
lines_fit = all(
len(l) <= self.len_limit - chunk.start_idx for l in lines
)
converted = converted.replace("\\n", "\n")
else:
lines_fit = (
len("".join([converted, rest])) <= self.len_limit - chunk.start_idx
)
else:
lines_fit = True
if not contract_lines or lines_fit:
self.results.append(converted)
self.count_expressions += 1
def transform_chunk(
code: str, quote_type: str = QuoteTypes.triple_double
) -> Tuple[str, bool]:
"""Convert a block of code to an f-string
Args:
code: The code to convert.
quote_type: the quote type to use for the transformed result
Returns:
Tuple: resulting code, boolean: was it changed?
"""
try:
tree = ast.parse(code)
converted, changed, str_in_str = fstringify_node(copy.deepcopy(tree))
except (SyntaxError, FlyntException, Exception) as e:
if state.verbose: