A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2015-September/141715.html below:

[Python-Dev] PEP 498 (interpolated f-string) tweak

[Python-Dev] PEP 498 (interpolated f-string) tweak [Python-Dev] PEP 498 (interpolated f-string) tweakEric V. Smith eric at trueblade.com
Sat Sep 19 13:03:05 CEST 2015
While finishing up the implementation of PEP 498, I realized that the
PEP has an error. It says that this code:

f'abc{expr1:spec1}{expr2!r:spec2}def{expr3:!s}ghi'

Is equivalent to:

'abc' + expr1.__format__(spec1) + repr(expr2).__format__(spec2) + 'def'
+ str(expr3).__format__('') + 'ghi'

But that's not correct. The right way to call __format__ is:

type(expr1).__format__(expr1, spec1)

That is, the lookup of __format__ is done on the type, not the instance.

Instead of calling __format__, I've changed the code generator to call
format(expr1, spec1). As an optimization, I might add special opcodes to
deal with this and string concatenation, but that's for another day (if
ever).

I've posted a new version of the code in issue 24965. I'll update the
PEP itself sometime this weekend.

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4