At least as posted here, you have a space after the backslash.
A backslash continuation is a backslash followed by a newline. A backslash followed by a space followed by a newline is just a backslash-escaped space, and an unescaped newline.
This is, of course, hard to see in most text editors, and on sites like Stack Overflow (I had to click "edit" on your question and scroll the cursor around to check), which is one of the reasons many people avoid backslash continuations whenever possible.
And it's especially a problem using them in strings, because a backslash-escaped space is a perfectly legal thing to put in a string, so the compiler won't give you an error about it, and even most linters won't warn about it.
If you can configure your editor to recognize backslashed whitespace and display it in some way, or maybe just to show you all newlines with some subtle marker, it may be helpful.
A better solution—assuming you actually want a newline there—is to use triple quotes:
warnings.warn('''blabla
continuing writing''')
… possibly with textwrap.dedent
so you can line things up nicely:1
from textwrap import dedent as D
warnings.warn(D(
'''blabla
continuing writing'''))
… or to use an explicit \n
:
warnings.warn('blabla\ncontinuing writing')
… possibly together with string concatenation:
warnings.warn('blabla\n'
'continuing writing')
(Depending on the purpose of this output, it also might be worth considering not worrying about exactly where the newlines go and letting textwrap.fill
take care of making it fit the output.)
1. However, it's worth noting that the examples in the textwrap
docs actually use backslash-escaped newlines to feed to dedent
, allowing you to put the triple-quote on one line and the start of the text on the next...