t-strings should be used for this.
Instead of your
some_sql = d'''sql
select * from
...long_table_expression...
...long_table_expression...
...long_table_expression...
where foo
'''
you should be writing
some_sql = some_sql_library.SQL(t'''
select * from
...long_table_expression...
...long_table_expression...
...long_table_expression...
where foo
''')
The idea here (though I don’t know if this has actually been implemented anywhere yet) is that if some_sql_library.SQL is appropriately typed and your editor has appropriate support, the content of the t-string will be automatically known to be SQL and highlighted appropriately. We shouldn’t be adding a second way to do this, and a Markdown-style tag immediately before or after the leading (triple-)quote isn’t as useful/flexible as an actual expression that can be evaluated at type-checking/static-analysis time or indeed at runtime (such as a function or class, here some_sql_library.SQL).
For my reasoning, please see my earlier explanation at PEP 750: Tag Strings For Writing Domain-Specific Languages - #161 by rrolls (and various other posts I made later in that thread).
Does it?
This is how I use triple-quoted strings:
# suppose there's some reason I'd be indented multiple times...
def foo(items):
for item in items:
if item.bar:
do_something_with_string('''
contents
of a rather long
triple-quoted
string
''')
do_something_else_conditionally()
do_something_else_with_item(item)
do_stuff_after_the_loop()
and I’ve never had any trouble with it.
On the contrary, if I were to align the contents of my string with the code, it starts to look like my string is Python code, and it can get very difficult to understand what is Python and what is string contents.
It’s also much more convenient to have my string contents left-aligned in the source code, because then I know I can use the same full width of a line (whatever the line width happens to be for the code style of the project I’m working on) regardless of the indentation level of the code where the triple-quoted string is placed.
I always place a newline at the beginning and end of my triple-quoted strings, so I don’t have anything after the opening ''' on its line, nor before the closing ''' on its line. If my string needs to not contain that extra pair of newlines, I just put [1:-1] immediately after the closing '''.
So maybe this would help people with certain code styles that call for the content of triple-quoted strings to be lined up with the code - but I’d argue that any potential benefit of adding something for that purpose would need to be weighed against the alternative of just suggesting that people adopt the pattern I’ve described here - which already works just fine.
Since these two points are the only purported benefits, I’d give a -1 overall.