[New-bugs-announce] [issue46992] If use textwrap.dedent with string formatting, may get unintended sentences.

김준환 report at bugs.python.org
Sat Mar 12 00:01:38 EST 2022


New submission from 김준환 <xncbf12 at gmail.com>:

If use textwrap.dedent with string formatting, may get unintended sentences.

For example, a sentence like this:

```
import textwrap

def get_something_string():
    return textwrap.dedent("""\
        test text2
        test text3
        test text4""")

textwrap.dedent(f"""\
    test text1
    {get_something_string()}
    test text5
    test text6""")
```

I look forward to the following results.

```
test text1
test text2
test text3
test text4
test text5
test text6
```

But the actual result is:
```
    test text1
    test text2
test text3
test text4
    test text5
    test text6
```

I understand that this code works in this way because the intent of the string defined inside the method is different from the intent of the string outside the method.

However, regular users, like me, will think of having a consistent intent result value. (because they believe dedent will clear a consistent intent)

If you are concerned that the existing code will be broken, I can implement the function using the flag parameter.

If you agree with my opinion, I will submit a PR.

----------
components: Library (Lib)
messages: 414972
nosy: xncbf12
priority: normal
severity: normal
status: open
title: If use textwrap.dedent with string formatting, may get unintended sentences.
type: behavior
versions: Python 3.10, Python 3.11, Python 3.7, Python 3.8, Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46992>
_______________________________________


More information about the New-bugs-announce mailing list