[issue46992] If use textwrap.dedent with string formatting, may get unintended sentences.
김준환 added the comment: x does not change. sorry. I also haven't figured out the implementation in my head yet. I want to provide some functionality to provide consistent indentation while using formatting . For example """ test {multi_line_text} """.format(multi_line_text, consistent_indent=True) It's just a suggestion. -- ___ Python tracker <https://bugs.python.org/issue46992> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue46992] If use textwrap.dedent with string formatting, may get unintended sentences.
김준환 added the comment: Sorry, Can't edit comments Please see the code example below ``` Class A: def get_something_string(): return textwrap.dedent("""\ test text2 test text3 test text4""") textwrap.dedent(f"""\ test text1 {A.get_something_string()} test text5 test text6""") ``` -- ___ Python tracker <https://bugs.python.org/issue46992> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue46992] If use textwrap.dedent with string formatting, may get unintended sentences.
김준환 added the comment: No, I know `textwrap.dedent` as a convenience function used for code readability. But to have the result I want, I currently need to do something like this: If it's a method inside a class, it's even more ugly. Class A: def get_something_string(): return textwrap.dedent("""\ test text2 test text3 test text4""") x = f"""\ test text1 {A.get_something_string()} test text5 test text6""" The duplicate use of dedent is to show an example. Thought I needed a consistent dedent for every line while using the string formatting feature. -- ___ Python tracker <https://bugs.python.org/issue46992> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue46992] If use textwrap.dedent with string formatting, may get unintended sentences.
김준환 added the comment: "<<" This marks that line. ignore it -- ___ Python tracker <https://bugs.python.org/issue46992> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue46992] If use textwrap.dedent with string formatting, may get unintended sentences.
김준환 added the comment: If it's only for version 3.11, what do you think of the default behavior of the dedent method being changed? The method description says: > Remove any common leading whitespace from every line in `text`. ``` 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 think it should work assuming that the indentation of {get_something_string()} and the indentation of test text2 are on the same line. -- versions: -Python 3.10, Python 3.7, Python 3.8, Python 3.9 ___ Python tracker <https://bugs.python.org/issue46992> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue46992] If use textwrap.dedent with string formatting, may get unintended sentences.
김준환 added the comment: Sorry, it's an indent , not an intent . -- ___ Python tracker <https://bugs.python.org/issue46992> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue46992] If use textwrap.dedent with string formatting, may get unintended sentences.
New submission from 김준환 : 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 <https://bugs.python.org/issue46992> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com