I thought about this point some time ago but I don't think it is a problem in general: - if you write a unit test you are likely to test your code without traverser so you will get plain Key errors - __getitem__ is not the place to put your application logic
If you want to extend pyramid or create a new framework on top you need to provide some code to be used by users. Either as base classes, decorators or pyramid level replacements. This doesn't mean users cannot use __getitem__. 2013/3/6 Peter Waller <[email protected]> > On 6 March 2013 10:21, Arndt Droullier <[email protected]> wrote: > >> I don't think you need to implement a new traverser you just need to >> provide a >> customized __getitem__ to be used by your users and handle all issues you >> described there. >> For example provide a decorator and introduce a NoRessource Exception and >> to be used >> instead of KeyError. >> > > Well, I want the users to write their own resources, and therefore > (potentailly) implement their own __getitem__. > > >> Though 'MultiTraverser' sounds like you already have replaced the >> default traverser? >> > > I was going to say here that I use `pyramid.traversal.traverse`, then I > realised that I do not. > > My code currently suffers from the same problem. Because "KeyError" is the > thing used to denote "no such resource", I can't tell the difference > between a non-existing resource and a programmer error. I can't currently > think of a way out of this, without changing pyramid's use of KeyError to > indicate no such resource in general :(. I'm sure this is a sign of bad > design on my part, but it does seem like KeyError to indicate no such > resource is also slightly problematic in general. > > I'm a little surprised I'm the first to raise this. Does anyone out there > agree with my point, or is this truly just unique to me? I guess in most > cases people are a) familiar with pyramid and that they have to be careful > not to accidentally raise KeyError, b) if they find themselves in a > no-such-resource situation it's obvious, c) if they find themselves in a > no-such-resource situation they know that they have to check for unexpected > KeyErrors. > > Are a)+b)+c) reasonable expectations for all pyramid developers? > > -- Arndt Droullier / Nive cms cms.nive.co -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/pylons-discuss?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
