Например, следующее выражение остался нетронутым.
Код: Выделить всё
f"""\
Hello {developer_name}
My name is {_get_machine(f"{self.prop_a}, {self.prop_b}")}
"""
Код: Выделить всё
f"""\
Hello {developer_name}
My name is {_get_machine(f"""{self.prop_a}, {self.prop_b}""")}
"""
Код: Выделить всё
class _FormattedStringEscapingTransformer(m.MatcherDecoratableTransformer):
@m.call_if_not_inside(
m.FormattedString(
parts=m.OneOf(
m.FormattedStringExpression(expression=m.TypeOf(m.FormattedString))
)
)
)
@m.leave(m.FormattedString())
def escape_f_string(
self, original_node: cst.FormattedString, updated_node: cst.FormattedString
) -> cst.FormattedString:
return updated_node.with_changes(start='f"""', end='"""')
Код: Выделить всё
class _FormattedStringEscapingTransformer(m.MatcherDecoratableTransformer):
@m.call_if_not_inside(
m.FormattedString(
parts=m.OneOf(
m.FormattedStringExpression(
expression=m.Not(m.FormattedString(parts=m.DoNotCare()))
)
)
)
)
@m.leave(m.FormattedString())
def escape_f_string(
self, original_node: cst.FormattedString, updated_node: cst.FormattedString
) -> cst.FormattedString:
return updated_node.with_changes(start='f"""', end='"""')
Какое правильное средство сопоставления исключает преобразование, если выражения внутренних f-строк?
Подробнее здесь: https://stackoverflow.com/questions/791 ... python-ast