diff --git a/pep-0498.txt b/pep-0498.txt index ade7f2d4c..1b9f39c9a 100644 --- a/pep-0498.txt +++ b/pep-0498.txt @@ -634,61 +634,6 @@ if written from scratch using f-strings. print("Usage: {0} [{1}]".format(sys.argv[0], '|'.join('--'+opt for opt in valid_opts)), file=sys.stderr) print(f"Usage: {sys.argv[0]} [{'|'.join('--'+opt for opt in valid_opts)}]", file=sys.stderr) -Implementation limitations -========================== - -Maximum of 255 expressions --------------------------- - -Due to a CPython limit with the number of parameters to a function, an -f-string may not contain more that 255 expressions. This includes -expressions inside format specifiers. So this code would count as -having 2 expressions:: - - f'{x:.{width}}' - -The same expression used multiple times ---------------------------------------- - -Every expression in an f-string is evaluated exactly once for each -time it appears in the f-string. However, when the same expression -appears more than once in an f-string, it's undefined which result -will be used in the resulting string value. This only matters for -expressions with side effects. - -For purposes of this section, two expressions are the same if they -have the exact same literal text defining them. For example, ``'{i}'`` -and ``'{i}'`` are the same expression, but ``'{i}'`` and ``'{i }'`` -are not, due to the extra space in the second expression. - -For example, given:: - - >>> def fn(lst): - ... lst[0] += 1 - ... return lst[0] - ... - >>> lst=[0] - >>> f'{fn(lst)} {fn(lst)}' - '1 2' - -The resulting f-string might have the value ``'1 2'``, ``'2 2'``, -``'1 1'``, or even ``'2 1'``. - -However:: - - >>> lst=[0] - >>> f'{fn(lst)} { fn(lst)}' - '1 2' - -This f-string will always have the value ``'1 2'``. This is due to the -two expressions not being the same: the space in the second example -makes the two expressions distinct. - -This restriction is in place in order to allow for a possible future -extension allowing translated strings, wherein the expression -substitutions would be identified by their text representations in the -f-strings. - References ==========