On Fri, 04 Jun 2004 11:59:46 +0200, Thomas Heller <theller at python.net> wrote: > > Couldn't Guido's syntax be implemented as a combination of an import > hook together with a byte code hack, without direct support in the core? > > Code like this > > [decorator1, decorator2] > def func(args): > pass How about this? [decorator1, decorator2] if 0: print "Obscure corner case?" def func(args): pass > seems to be compiled into these byte codes > .... > 6 BUILD_LIST > 9 POP_TOP > 10 LOAD_CONST 0 (<code object test at 0091FD20, ...) > 13 MAKE_FUNCTION 0 > 16 STORE_NAME 2 (test) > > It seems BUILD_LIST / POP_TOP / LOAD_CONST / MAKE_FUNCTION is the > sequence which should trigger the magic. I don't recall Guido's patch. Did he modify the grammar or can it all be done inside the compiler? Not that it's practical for 2.4, but I think it wouldn't be hard to post-process the existing AST to recognize decorators written like this. You'd like for adjacent statements of the form: Expr(List()) FunctionDef() and replace them with a single FunctionDef() Or do we need to catch Expr(ListComp()) too? PEP 318 doesn't mention semantics anywhere, so it doesn't say what is allowed inside the square brackets. Jeremy
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4