Message251073
I changed the generated code to call:
format(x [, spec])
instead of:
x.__format__(spec)
The reason is that the correct way to call __format__ is actually:
type(x).__format__(x, spec)
That is, the __format__ lookup is done on the type, not the instance. From the earlier example, the disassembled code is now:
>>> dis.dis("f'a={a}'")
1 0 LOAD_CONST 0 ('')
3 LOAD_ATTR 0 (join)
6 LOAD_CONST 1 ('a=')
9 LOAD_GLOBAL 1 (format)
12 LOAD_NAME 2 (a)
15 CALL_FUNCTION 1 (1 positional, 0 keyword pair)
18 BUILD_LIST 2
21 CALL_FUNCTION 1 (1 positional, 0 keyword pair)
24 RETURN_VALUE
The simplest way to make the lookup correctly is just to call format() itself, which does the right thing.
I still have a concept of adding opcodes to handle FormattedValue and JoinedStr nodes, but that's an optimization for later, if ever. |
|
Date |
User |
Action |
Args |
2015-09-19 10:49:42 | eric.smith | set | recipients:
+ eric.smith, barry, python-dev, Rosuav, martin.panter, yselivanov, JelleZijlstra, elvis |
2015-09-19 10:49:42 | eric.smith | set | messageid: <1442659782.17.0.525887844968.issue24965@psf.upfronthosting.co.za> |
2015-09-19 10:49:42 | eric.smith | link | issue24965 messages |
2015-09-19 10:49:41 | eric.smith | create | |
|