# Pre-PEP: d-string / Dedented Multiline Strings with Optional Language Hinting

**URL:** <https://discuss.python.org/t/pre-pep-d-string-dedented-multiline-strings-with-optional-language-hinting/90988>\
**Category:** Ideas\
**Created:** [May 6, 2025, 5:00pm UTC](https://discuss.python.org/t/pre-pep-d-string-dedented-multiline-strings-with-optional-language-hinting/90988 "2025-05-06T17:00:30Z")\
**Posts on this page:** 1\
**Showing post:** 13

<div class="post-metadata">

**Author:** ![blhsing](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/blhsing/32/25812_2.png) [@blhsing](https://discuss.python.org/u/blhsing)\
**Post date:** [May 7, 2025, 2:35am UTC](https://discuss.python.org/t/pre-pep-d-string-dedented-multiline-strings-with-optional-language-hinting/90988/13 "2025-05-07T02:35:55Z")

</div>

> [@blhsing](#):
>
> > [@bwoodsend](#):
> >
> > It would also make long literals so much cleaner. Every time I want to write a halfway nontrivial error message I always wish I could just write…
> > 
> > ```python
> > raise SomeException(d"""
> > Some explanation that is longer than the ~60 characters of width \
> > I normally have left at this point because I'm already a few \
> > levels of indentation deep. Blah de blah de blah.
> > """)
> > 
> > ```
> 
> Very interesting. Using the line continuation marker as a way to suppress newlines while dedenting the next lines goes beyond what `textwrap.dedent` currently has to offer and actually requires changes to the parser/tokenizer for this to happen. Adds complexity to the implementation for sure but would actually make the proposal a clear win over the status quo of using `textwrap.dedent`. Would love to see this feature included.

On second thought, it is usually unlikely that you would have some lines with line continuation markers and some without, in a single string literal. So instead of a line continuation marker at the end of every line, which adds noise to both reading and writing, we may allow a “line continuation mode” through a different prefix such as `D`.

```python
        raise SomeException(D"""
            Some explanation that is longer than the ~60 characters of width 
            I normally have left at this point because I'm already a few 
            levels of indentation deep. Blah de blah de blah.
        """) # results in a dedented string with no newlines

```

The line continuation marker feature may still be useful when there are mutiple paragraphs:

```python
        raise SomeException(d"""
            Some explanation that is longer than the ~60 characters of width \
            I normally have left at this point because I'm already a few \
            levels of indentation deep.

            - detail #1: ...
            - detail #2: ...
        """)

```

although the above may also be accomplished with concatenation of two string literals, depending on personal preferences:

```python
        raise SomeException(D"""
            Some explanation that is longer than the ~60 characters of width 
            I normally have left at this point because I'm already a few 
            levels of indentation deep.
        """
        d"""
            - detail #1: ...
            - detail #2: ...
        """)

```

---

_[View the full topic](https://discuss.python.org/t/pre-pep-d-string-dedented-multiline-strings-with-optional-language-hinting/90988)._
