On Aug 16, 6:17 pm, Christoph Zwerschke <c...@online.de> wrote:
> Am 16.08.2010 23:35 schrieb Phillip J. Eby:
>
> > I went ahead and pushed out a new snapshot (r2672) with both a fix and
> > the new priority() feature.  Sorry again about the mixup.
>
> Thanks for the quick response, Phillip. I will use that feature in
> TurboJson then.
>
> -- Christoph

By the way, I was just writing something for my blog about avoiding
AmbiguousMethod errors *without* using priorities; I'm curious whether
it might help you.  I was actually writing it based on the one jsonify-
like use case that I knew about that was causing ambiguous method
errors, and I just took a look at how TurboJson is using priorities.

Essentially, the issue is that you're putting what are basically your
fallback cases in rules, instead of in the main method body.  If you
just put all your default cases in the main function body (instead of
using @abstract), then those rules can't ever be ambiguous.

But, if you *really* want to use rules to incrementally define your
default cases, just define them on an abstract "jsonify_default()"
function, then make a concrete jsonify like this:

    def jsonify(ob):
        return jsonify_default(ob)

Voila...  you now have the equivalent of your "prio=-1" rules, while
any rules defined on jsonify() itself will have "higher priority", and
*can't* be ambiguous with any of your default rules.

Alternately, if the real issue is just conflicts with the lookup for
'__json__', you can do this:

    @around(jsonify, "hasattr(ob, '__json__')")
    def jsonify_explicit(obj):
        """JSONify objects with explicit JSONification method."""
        return obj.__json__()

Then, you don't have to put in all those "and not hasattr" conditions
everywhere else, because the explicit version will always take
precedence if an object has the __json__ attribute.

So, I guess what I'm saying is that PEAK-Rules has *always* had
priorities -- they're just called "putting the base cases in the body"
and "use @around methods for things that need to take precedence over
everything else".

I'm wondering whether these would solve your problems without the use
of priorities.

-- 
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to turboge...@googlegroups.com.
To unsubscribe from this group, send email to 
turbogears+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en.

Reply via email to