[Python-checkins] peps: Added a note that the str.format() parser is not suitable for use when

eric.smith python-checkins at python.org
Thu Aug 27 16:19:52 CEST 2015


https://hg.python.org/peps/rev/a3faab8fb10a
changeset:   5997:a3faab8fb10a
user:        Eric V. Smith <eric at trueblade.com>
date:        Thu Aug 27 10:20:59 2015 -0400
summary:
  Added a note that the str.format() parser is not suitable for use when implementing f-strings.

files:
  pep-0498.txt |  9 +++++++++
  1 files changed, 9 insertions(+), 0 deletions(-)


diff --git a/pep-0498.txt b/pep-0498.txt
--- a/pep-0498.txt
+++ b/pep-0498.txt
@@ -470,6 +470,15 @@
   >>> f'a={d[a]}'
   'a=20'
 
+Furthermore, the limited expressions that str.format() understands
+need not be valid Python expressions. For example::
+
+  >>> '{i[";]}'.format(i={'";':4})
+  '4'
+
+For this reason, the str.format() "expression parser" is not suitable
+for use when implementing f-strings.
+
 See [#]_ for a further discussion. It was this observation that led to
 full Python expressions being supported in f-strings.
 

-- 
Repository URL: https://hg.python.org/peps


More information about the Python-checkins mailing list