PEP 312 (and thus 308) implemented with a black magic trick
tjreedy at udel.edu
Wed Mar 19 18:21:24 CET 2003
"Andrew Bennetts" <andrew-pythonlist at puzzling.org> wrote in message
news:mailman.1048071128.22193.python-list at python.org...
> On Mon, Mar 17, 2003 at 01:58:28PM -0800, Michele Simionato wrote:
> > Today I had an illumination on how to implement both PEP 312 and
> > in current Python. I think I will share the idea, even if I would
> > recommend to use such a dirty trick in production code.
> Nasty. :)
> So, who's going to be the first to implement ++x using this
If, as I understand, this meta technique relies on source text, this
should work. But not if it looks at code:
>>> def f(): return ++1
>>> import dis
0 SET_LINENO 1
3 SET_LINENO 1
6 LOAD_CONST 1 (1)
11 LOAD_CONST 0 (None)
Compiler seems to optimize away second unary positive.
Terry J. Reedy
More information about the Python-list