[Zope3-dev] calling objects when evaluating path expressions

Shane Hathaway shane@zope.com
Fri, 20 Jun 2003 11:12:39 -0400


Steve Alexander wrote:
> Shane Hathaway wrote:
>> 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.

Yes, it's not what the user wants.

> I can't find Guido's enhancement just now. Perhaps he posted it via his 
> time-machine.

Rather than "enhancement", I should have just called it a "follow-up".

http://mail.zope.org/pipermail/zope3-dev/2003-June/007373.html

> 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.

I agree that's a weakness of depending on properties, but calling things 
  automatically is a bit magical and fragile.

Here's another approach that doesn't add any syntax.  Recently, we added 
the ability to use prefixes in the middle of path expressions, so 
perhaps we could define the "call:" prefix to mean "call the method 
named X, passing no arguments".

<span tal:replace="foo/call:bar/baz" />

On a related note, a few other prefixes could disambiguate traversal. 
Consider the problem of fetching an item called "keys" from a dictionary 
using a path expression.  Unless Zope 3 has changed the policy, basic 
traversal tries attributes first and items second, so path expressions 
can't easily access items with certain names.  An "item:" prefix could 
solve this.

Shane