Brian Granger wrote: >> Yes, this is a bug. Does anyone have an idea how to fix it? Maybe the >> handlers_dict.update should be our own method and it should raise an >> exception if one key is updated twice? E.g. one would first have to >> remove the key, then register it. Then the user will know that two >> packages use the same key at least. > > Does it make logical sense to have more than 1 query for an assumption type: > > register_query_handler('associative',FooAssociativeQueryHandler) > register_query_handler('associative',BarAssociativeQueryHandler) > > The internal data structure would be a dict of lists, keyed by things > like 'associative'. > > I guess what I don't know is if the assumption system is setup to go > through a sequence > of handlers or if that makes sense. Thinking out loud here... > > If different QueryHandlers implement methods for different types: > > class FooAssociativeQueryHandler(QueryHandler): > def Symbol(self): > return True > > class BarAssociativeQueryHandler(QueryHandler): > def Number(self): > return True > > I can imagine that you can go through and try each handler. The issue > is when more than one handler tries to handle a single type. The only > thing I can think of then is to have a priority system, where the > handlers are tried in order of increasing priority and the final value > (the highest priority one) wins.
Knowing it or not, you gave me the answer to a far more important problem !!. The problem of extensibility with respect to user-defined types (as opposed to extensibility with respect to user-defined queries) Suppose you have a self-defined type and you want to use existing query keys with that type, for example: >>> x = MySymbol('x') >>> query(x, commutative=True) None Now, having multiple QueryHandlers for one query would permit us to define: class xCommutativeHandler(QueryHandler): def MySymbol(self): return True then >>> register_query_handler('commutative',xCommutativeQueryHandler) and queries would work with class MySymbol: >>> query(x, commutative=True) True I think it's a clever way of solving both extensibility on types and on queries. As to your original question, when two queryhandlers clash on a specific method, for consistency I think we should evaluate both and return the most specific result, or raise an exception if they contradict, that is: 1. If both handlers return None --> return None 3. If one returns a bool and the other one None --> return the bool 4. If both handlers return the same bool --> return that bool 5. If they return different booleans --> raise Exception Thanks, > > Cheers, > > Brian > > > > -- http://fseoane.net/blog/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sympy-patches" group. To post to this group, send email to sympy-patches@googlegroups.com To unsubscribe from this group, send email to sympy-patches+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sympy-patches?hl=en -~----------~----~----~----~------~----~------~--~---