Chris Wilcox <pyt...@crwilcox.com> added the comment:

Double curly braces do not indicate to not process the inner content. They 
indicate to include a literal curly brace. That said, I think there may be 
something not quite correct.

I came up with an example based on the example in the format specifiers section 
of the PEP.

>From the PEP.
```
>>> width = 10
>>> precision = 4
>>> value = decimal.Decimal('12.34567')
>>> f'result: {value:{width}.{precision}}'
'result:      12.35'
```
The template in this instance is "10.4"

If we leave the sample the same, but don't wrap width or precision in single 
curly braces,
```
>>> f'result: {value:width.precision}'
```
I would expect the template "width.precision".

Further, I would expect
```
>>> f'result: {value:{{width}}.{{precision}}}'
```
to have a template of "{width}.{precision}". This is not the case.


Here is some code that should demonstrate this.
```
class Decimal:
    def __init__(self, value):
        pass
    def __format__(self, template):
        return template
width = 10
precision = 4
value = Decimal('12.34567')
print("Expect Template to be '10.4' (TRUE)")
print(f'result0: {value:{width}.{precision}}')
print("Expect Template to be 'width.precision' (TRUE)")
print(f'result1: {value:width.precision}')
print("Expect Template to be '{width}.{precision}' (FALSE)")
print(f'result2: {value:{{width}}.{{precision}}}') # ACTUAL: {10}.{4}
```

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue39601>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to