Skip to content

Commit d1415ef

Browse files
methaneCopilot
andauthored
PEP 822: add a Rejected Idea (#4795)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent fbf9be9 commit d1415ef

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

peps/pep-0822.rst

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,12 @@ triple quote, it removes indent from text too.
334334
Ruby also has `"squiggly" heredoc <https://ruby-doc.org/core-2.5.0/doc/syntax/literals_rdoc.html#label-Here+Documents>`__
335335
that removes indent from lines in heredoc.
336336

337+
Perl has `"Indented Here-documents <https://perldoc.perl.org/perl5260delta#Indented-Here-documents>`__
338+
since Perl 5.26 as well.
339+
337340
Java, Julia, and Ruby uses the least-indented line to determine the amount of
338341
indentation to be removed.
339-
Swift, C#, and PHP uses the indentation of the closing triple quotes or
342+
Swift, C#, PHP, and Perl use the indentation of the closing triple quotes or
340343
closing marker.
341344

342345

@@ -469,6 +472,38 @@ quotes, these workarounds are not necessary when rewriting ``textwrap.dedent()``
469472
to d-strings.
470473

471474

475+
Allow content after opening quotes
476+
----------------------------------
477+
478+
There was also a proposal to allow writing content immediately after
479+
the opening quotes, just like existing ``"""``.
480+
481+
Since closing quotes can be on the same line as content, it looks symmetrical
482+
to allow content right after opening quotes too.
483+
And it would make it easier to rewrite existing ``"""`` to d-strings.
484+
485+
On the other hand, it increases the number of syntax rules that readers need to
486+
remember in order to understand how much indentation will be removed.
487+
488+
Also, allowing content after opening quotes would not resolve the usability
489+
issue where existing ``textwrap.dedent("""...""")`` users must write
490+
``"""\<newline>`` to avoid including the first newline.
491+
Julia avoids this issue by removing the first newline when starting with
492+
``"""<newline>``, but this adds another syntax rule that users need to remember.
493+
494+
Since we rejected the idea of using a ``__future__`` import, we prioritized
495+
ease of use for users rewriting from ``textwrap.dedent()`` or those who
496+
wanted to use ``textwrap.dedent()`` but couldn't for some reason, over
497+
the ease of rewriting existing multiline string literal users to d-strings.
498+
499+
Additionally, `in past discussions <https://discuss.python.org/t/90988>`__,
500+
there was a proposal to allow writing hints or comments for syntax highlighting
501+
immediately after the opening quote.
502+
That proposal was rejected to move the d-string discussion forward, but by not
503+
allowing anything right after the opening quote, it leaves room for possibly
504+
allowing comments there in the future.
505+
506+
472507
Copyright
473508
=========
474509

0 commit comments

Comments
 (0)