Eric V. Smith added the comment:
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.
----------
Added file: http://bugs.python.org/file40515/pep-498-10.diff
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue24965>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com