pre-PEP: Suite-Based Keywords - syntax proposal
Kay Schluehr
kay.schluehr at gmx.net
Mon Apr 18 01:07:39 EDT 2005
Steven Bethard wrote:
> So the object of a "where" is then always an ordered dict?
Yes.
> If so, then
> I guess I like this proposal best so far.
>
> However, it does seem to have the problem that you can't have any
> additional local variables so, for example, list comprehensions are
> probably not usable...
>
> Or can you still drop the argument to "where" and just use the names
> directly? E.g.:
>
> x = property(fget=fget, doc=doc) where:
> doc = "I'm the 'x' property."
> def fget(self):
> return self.__x
I can't see why this shouldn't work?
The specifiers behind "where" are present to determine the matching
behaviour. The order of a dict is caused by different specifiers i.e. a
dict- or tuple-like specifier. If a specifier is not present only names
can be matched regardless of a sequence and this is always possible
because we still have a dict with names as keys.
What should not be possible are statements like this:
x = property(a, b) where:
doc = "I'm the 'x' property."
def fget(self):
return self.__x
because there is no rule to match doc and fget onto a and b. In this
case we would need specifiers:
x = property(a, b)
where **a:
doc = "I'm the 'x' property."
where **b:
def fget(self):
return self.__x
Ciao,
Kay
More information about the Python-list
mailing list