<h2 style="margin:1.3125em 0px 0.32813em;padding:0px;border:0px;font-weight:normal;vertical-align:baseline"><font size="2"><span style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.301961);">PEP 498:</span></font></h2><div><font size="2"><span style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.301961);">"""</span></font></div><h2 style="margin:1.3125em 0px 0.32813em;padding:0px;border:0px;font-weight:normal;vertical-align:baseline"><font color="#000000" size="2" style="border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(255,223,118);display:inline;background-color:rgba(255,255,255,0)">Leading<a class="toc-backref" href="https://www.python.org/dev/peps/pep-0498/#id28" style="border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(255,223,118);display:inline;background-color:rgba(255,255,255,0)"> whitespace in expressions is skipped</a></font></h2><p style="margin:0px 0px 1.3125em;padding:0px;border:0px;vertical-align:baseline"><font size="2"><span style="background-color:rgba(255,255,255,0)">Because expressions may begin with a left brace ('{'), there is a problem when parsing such expressions. For example:</span></font></p><pre class="literal-block" style="margin-top:0px;margin-bottom:1.3125em;padding:0.5em;border:0px;vertical-align:baseline;word-wrap:break-word;background-image:inherit"><font face="Helvetica Neue, Helvetica, Arial, sans-serif" size="3"><span style="white-space:normal;background-color:rgba(255,255,255,0)">>>> f'{{k:v for k, v in [(1, 2), (3, 4)]}}'
'{k:v for k, v in [(1, 2), (3, 4)]}'</span></font><span style="color:rgb(68,68,68);font-family:Consolas,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,sans-serif;line-height:1.875;background-color:inherit">
</span></pre><div>"""</div><div><br></div>For me, this example is crazy. You should not add a special case (ignore spaces) just to support a corner case.<div><br></div><div>This example can easily be rewritten using a temporary variable and it makes the code simpler.</div><div><font face="Helvetica Neue, Helvetica, Arial, sans-serif" size="3" style="white-space:pre-wrap"><span style="white-space:normal;background-color:rgba(255,255,255,0)"><br></span></font></div><div><font face="Helvetica Neue, Helvetica, Arial, sans-serif" size="3" style="white-space:pre-wrap"><span style="white-space:normal;background-color:rgba(255,255,255,0)">items={k:v for k, v in [(1, 2), (3, 4)]; </span></font><span style="font-size:medium;background-color:rgba(255,255,255,0)">f'{items</span><span style="font-size:medium;background-color:rgba(255,255,255,0)">}'</span></div><div><br></div><div>Seriously, a dict-comprehension inside a f-string should be considered as an abuse of the feature. Don't you think so?</div><div><br></div><div>Victor</div>