[Zope3-dev] calling objects when evaluating path expressions
Steve Alexander
steve@cat-box.net
Fri, 20 Jun 2003 17:06:48 +0300
Shane Hathaway wrote:
> Steve Alexander wrote:
>
>> However, the following gives an unexpected result.
>>
>> <span tal:replace="foo/bar/spoo" />
>>
>> result:
>>
>> <bound method baz of <Foo object at 0x92c668c>>
>
>
> This result is surprising because it should have thrown an error. It
> should not have attempted to call foo.bar, and attempting to find "spoo"
> should have raised an AttributeError.
Ok. I think my example was wrong. I think it probably does raise an
AttributeError.
I still say that, from the page-template-user's point of view, an
AttributeError is an unexpected result.
> I agree with your proposal and Guido's enhancement--we should rely on
> properties now and not attempt to call anything in path expressions.
I can't find Guido's enhancement just now. Perhaps he posted it via his
time-machine.
> I once considered suggesting a minor enhancement to path expressions to
> deal with this: use an exclamation point to call things. For example::
>
> <span tal:replace="foo/bar!/spoo" />
>
> As exciting as this makes page templates look <wink>, it could be
> redundant. The class author could just create a property instead.
I'd rather not see any more odd symbols in path expressions.
But, you're right: it does make them more exciting :-)
One of the goals of page templates in Zope 3 is to allow them to present
content classes that were not written with such use in mind. So, in Zope
3 we cannot assume that properties are always provided where appropriate.
We can address this in Zope 3 by using view classes, and by making the
default traversable component call simple things we want to be called,
and by providing traversable components for other components.
--
Steve Alexander