Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Newline escapes are removed #83

Open
jdufresne opened this issue Nov 30, 2020 · 2 comments
Open

Newline escapes are removed #83

jdufresne opened this issue Nov 30, 2020 · 2 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@jdufresne
Copy link

jdufresne commented Nov 30, 2020

input:

from textwrap import dedent

def f():
    arg = "text"
    return dedent(
        """\
        some {}
        lorem ipsum
        """.format(arg)
    )

expected:

from textwrap import dedent

def f():
    arg = "text"
    return dedent(
        f"""\
        some {arg}
        lorem ipsum
        """
    )

actual:

from textwrap import dedent

def f():
    arg = "text"
    return dedent(
        f"""        some {arg}
        lorem ipsum
        """
    )

The newline escape was intentionally introduced to make the dedent block more readable.

@ikamensh
Copy link
Owner

ikamensh commented Dec 5, 2020

Hi, thanks for reporting the bug. Similarly to #55 the problem lays in the symbols being gone from the parsed expression (escaping the newline has the specific purpose of removing this newline as seen by the interpreter).

I imagine a solution would be to find the diff on the parsed version of the code, and then apply this diff to the original section of the code. From fast research, this library could do this: https://pypi.org/project/diff-match-patch/. Yet this means very deep reworking of the library internals to adopt this new method of deriving new code. I can't provide any ETA on this.

@ikamensh ikamensh added help wanted Extra attention is needed bug Something isn't working labels Dec 5, 2020
@akx
Copy link
Contributor

akx commented Nov 22, 2022

I think doing this robustly would require something like https://github.com/Instagram/LibCST instead of just working with the AST.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants