[Python-Dev] Defining properties - a use case for class decorators? (original) (raw)
Phillip J. Eby pje at telecommunity.com
Wed Oct 19 17:42:05 CEST 2005
- Previous message: [Python-Dev] Defining properties - a use case for class decorators?
- Next message: [Python-Dev] Defining properties - a use case for class decorators?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
At 07:47 PM 10/19/2005 +1000, Nick Coghlan wrote:
Phillip J. Eby wrote: > Note that a "where" or "given" statement like this could make it a > little easier to drop lambda.
I think the "lambda will disappear in Py3k" concept might have been what triggered the original 'where' statement discussion. The idea was to be able to lift an arbitrary subexpression out of a function call or assignment statement without having to worry about affecting the surrounding namespace, and without distracting attention from the original statement. Basically, let a local refactoring stay local. The discussion wandered fairly far afield from that original goal though. One reason it fell apart was trying to answer the seemingly simple question "What would this print?": def f(): a = 1 b = 2 print 1, locals() print 3, locals() given: a = 2 c = 3 print 2, locals() print 4, locals()
It would print "SyntaxError", because the 'given' or 'where' clause should only work on an expression or assignment statement, not print. :)
In Python 3000, where print is a function, it should print the numbers in sequence, with 1+4 showing the outer locals, and 2+3 showing the inner locals (not including 'b', since b is not a local variable in the nested block).
I don't see what's hard about the question, if you view the block as syntax sugar for a function definition and invocation on the right hand side of an assignment.
Of course, if you assume it can occur on any statement (e.g. print), I suppose things could seem more hairy.
- Previous message: [Python-Dev] Defining properties - a use case for class decorators?
- Next message: [Python-Dev] Defining properties - a use case for class decorators?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]