homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eric.smith
Recipients JelleZijlstra, Rosuav, barry, elvis, eric.smith, martin.panter, python-dev, yselivanov
Date 2015年09月19日.10:49:29
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1442659782.17.0.525887844968.issue24965@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2015年09月19日 10:49:42eric.smithsetrecipients: + eric.smith, barry, python-dev, Rosuav, martin.panter, yselivanov, JelleZijlstra, elvis
2015年09月19日 10:49:42eric.smithsetmessageid: <1442659782.17.0.525887844968.issue24965@psf.upfronthosting.co.za>
2015年09月19日 10:49:42eric.smithlinkissue24965 messages
2015年09月19日 10:49:41eric.smithcreate

AltStyle によって変換されたページ (->オリジナル) /