Love the PEP, I think it’s very well argued and thought-through!
I can understand how you arrive at this from the POV of the algorithm that determines the indentation of the trailing triple-quote and deducts that from all the lines, but this restriction seems artificial to me.
Taking the two relevant of your examples, I don’t see how
s = d"""Hello
__World!
"""
print(repr(s)) # 'Hello\n__World!\n'
s = d"""\
__Hello
__World
__"""
print(repr(s)) # 'Hello\nWorld!\n'
would have any ambiguity in their mechanics. Likewise for the following third example that ties both cases together
s = d"""Hello\
__World!\
__"""
print(repr(s)) # 'HelloWorld!'
The way I read this is that the line containing the opening triple quotes simply does not participate in the stripping of indentation. This is IMO still a rule that’s very intuitively explainable[1]. As any feature, it has some potential for suboptimal use, e.g.
s = d"""__Hello
______World!
____"""
print(repr(s)) # '__Hello\n__World!\n'
but I think that’s where we should rely on “consenting adults” being able to make the choices they prefer (and of course popular linters will come up with best practice rules anyway).
To summarise: I think it’s imperative to avoid ambiguity, but I also think it’d be better to avoid restrictions that aren’t strictly necessary for that.
not least because the position of the opening quotes will generally be different from the rest of the multi-line string anyway. ↩︎