[PEAK] Use cases for the priority feature

Alberto Valverde alberto at toscat.net
Tue Aug 17 19:53:13 EDT 2010


  On 8/18/10 12:56 AM, P.J. Eby wrote:
> At 11:48 PM 8/17/2010 +0200, Alberto Valverde wrote:
>>  Hi,
>>
>> Another use-case for the priority feature is when you're extending a 
>> framework's generic function (eg: jsonify) and you can't (or don't 
>> want to) modify its source to avoid a conflict with the rule you want 
>> to register. In this hypothetical case "around" can't be used either 
>> since the framework (or another library) already defines an around 
>> method. The only way would be to write a more specific rule but this 
>> can be tedious and verbose.
>
> Hm.  Maybe I should just add a way to remove or replace an existing 
> method, e.g.:
>
>    remove(func, "condition")
>
> There is already "rules_for(func).remove(rule)", but you must know the 
> rule object.  I could add something to let you find the rules matching 
> a specific condition.
>
> This seems more explicit to me than just sticking a magic number on 
> the end of something.

I agree, that will cover this use case much better, which is about 90% 
of my needs I guess for the concept of a priority. In fact, this was 
originally the the reason to "resurrect" prioritized_methods (see: [1]). 
Maybe the remaining are covered by the method combination examples 
posted in this thread (or variations thereof) but I need to give it a 
better thought... (and reload some code)
> I also could potentially add a 'replace' keyword argument to 
> decorators, so you can replace an existing rule -- and you'd get an 
> error if you tried to replace something that didn't exist.
Why an error? I guess that would force to catch it and retry in the most 
common case (i guess) which would be "register this, no matter what the 
framework or framework-add-on might have registered". Perhaps it would 
be more usable by behaving like a dict.__setitem__ along with a 
has_signature("some cond"|SomeClass|etc...) to look-before-you-leap if 
really needed?

Alberto.

P.S I'll be traveling tomorrow and need to sleep now, will follow up in 
this and other threads in a later this week.

[1] 
http://groups.google.com/group/turbogears-trunk/browse_thread/thread/36e5356453e94e93/


More information about the PEAK mailing list