[Python-Dev] PEP 498 (interpolated f-string) tweak

2015-09-19 Thread Eric V. Smith
While finishing up the implementation of PEP 498, I realized that the PEP has an error. It says that this code: f'abc{expr1:spec1}{expr2!r:spec2}def{expr3:!s}ghi' Is equivalent to: 'abc' + expr1.__format__(spec1) + repr(expr2).__format__(spec2) + 'def' + str(expr3).__format__('') + 'ghi' But th

Re: [Python-Dev] PEP 498 (interpolated f-string) tweak

2015-09-19 Thread Guido van Rossum
Good catch, Eric. For those who wonder what the difference is or why it matters, it's what we do for all dunder operators: the magic method is looked up on the class, not on the instance. This means you can't e.g. override + on a per-instance basis by having an instance variable named '__add__' po

Re: [Python-Dev] PEP 498 (interpolated f-string) tweak

2015-09-19 Thread Serhiy Storchaka
On 19.09.15 14:03, Eric V. Smith wrote: While finishing up the implementation of PEP 498, I realized that the PEP has an error. It says that this code: f'abc{expr1:spec1}{expr2!r:spec2}def{expr3:!s}ghi' Is equivalent to: 'abc' + expr1.__format__(spec1) + repr(expr2).__format__(spec2) + 'def' +

Re: [Python-Dev] PEP 498 (interpolated f-string) tweak

2015-09-19 Thread Eric V. Smith
On 9/19/2015 3:22 PM, Serhiy Storchaka wrote: > On 19.09.15 14:03, Eric V. Smith wrote: >> While finishing up the implementation of PEP 498, I realized that the >> PEP has an error. It says that this code: >> >> f'abc{expr1:spec1}{expr2!r:spec2}def{expr3:!s}ghi' >> >> Is equivalent to: >> >> 'abc'

Re: [Python-Dev] PEP 498 (interpolated f-string) tweak

2015-09-19 Thread Eric V. Smith
On 9/19/2015 3:36 PM, Eric V. Smith wrote: > On 9/19/2015 3:22 PM, Serhiy Storchaka wrote: >> On 19.09.15 14:03, Eric V. Smith wrote: >>> Instead of calling __format__, I've changed the code generator to call >>> format(expr1, spec1). As an optimization, I might add special opcodes to >>> deal with

Re: [Python-Dev] PEP 498 (interpolated f-string) tweak

2015-09-19 Thread Chris Angelico
On Sun, Sep 20, 2015 at 5:36 AM, Eric V. Smith wrote: > As the PEP says, the expression with '+' is illustrative, not how it's > actually implemented. The implementation currently uses ''.join, > although I reserve the right to change it. > >> or even to >> >> 'abc{:spec1}{!r:spec2}def{!s}ghi'

Re: [Python-Dev] PEP 498 (interpolated f-string) tweak

2015-09-20 Thread Nick Coghlan
On 19 September 2015 at 21:03, Eric V. Smith wrote: > While finishing up the implementation of PEP 498, I realized that the > PEP has an error. It says that this code: > > f'abc{expr1:spec1}{expr2!r:spec2}def{expr3:!s}ghi' > > Is equivalent to: > > 'abc' + expr1.__format__(spec1) + repr(expr2).__f

Re: [Python-Dev] PEP 498 (interpolated f-string) tweak

2015-09-20 Thread Eric V. Smith
On 9/20/2015 8:37 AM, Nick Coghlan wrote: > On 19 September 2015 at 21:03, Eric V. Smith wrote: >> Instead of calling __format__, I've changed the code generator to call >> format(expr1, spec1). As an optimization, I might add special opcodes to >> deal with this and string concatenation, but that

Re: [Python-Dev] PEP 498 (interpolated f-string) tweak

2015-09-20 Thread Serhiy Storchaka
On 20.09.15 16:51, Eric V. Smith wrote: On 9/20/2015 8:37 AM, Nick Coghlan wrote: On 19 September 2015 at 21:03, Eric V. Smith wrote: Instead of calling __format__, I've changed the code generator to call format(expr1, spec1). As an optimization, I might add special opcodes to deal with this a

Re: [Python-Dev] PEP 498 (interpolated f-string) tweak

2015-09-20 Thread Eric V. Smith
> On Sep 20, 2015, at 11:15 AM, Serhiy Storchaka wrote: > >> On 20.09.15 16:51, Eric V. Smith wrote: >>> On 9/20/2015 8:37 AM, Nick Coghlan wrote: On 19 September 2015 at 21:03, Eric V. Smith wrote: Instead of calling __format__, I've changed the code generator to call format(exp

Re: [Python-Dev] PEP 498 (interpolated f-string) tweak

2015-09-21 Thread Nick Coghlan
On 21 September 2015 at 05:22, Eric V. Smith wrote: > >> On Sep 20, 2015, at 11:15 AM, Serhiy Storchaka wrote: >> >>> On 20.09.15 16:51, Eric V. Smith wrote: On 9/20/2015 8:37 AM, Nick Coghlan wrote: > On 19 September 2015 at 21:03, Eric V. Smith wrote: > Instead of calling __format