On Wed, Jun 10, 2009 at 4:51 PM, Brian Granger<ellisonbg....@gmail.com> wrote:
>
>> yes, that's one of the main reasons behind writing the module!.
>
> Great!
>
>> I'll show by example how to create a new query without touching any file
>> in sympy's codebase :
>>
>> In [1]: from sympy.query import QueryHandler, handlers_dict
>>
>> In [2]: class AssociativeQueryHandler(QueryHandler):
>>    ...:     def Symbol(self):
>>    ...:         return True # we know Symbols are associative
>>    ...:     def Number(self):
>>    ...:         return True
>>    ...:
>>
>> In [3]: handlers_dict.update({'associative': AssociativeQueryHandler}) #
>> we tell the assumptions system that the associative query will be
>> handled by our class
>>
>> In [4]: query(x, associative=True) # voilá !
>> Out[4]: True
>>
>> In [5]: query(3, associative=True)
>> Out[5]: True
>>
>> As you see, you can add/remove query handlers at runtime without much
>> trouble.
>
> Wow, this is absolutely fantastic.  One question though.  Let's say
> two different packages define some new Sympy objects and some queries
> along with them.  And let's say that merely importing those packages
> causes them to register their queries under the same key.
>
> Making it more concrete, if package foo and bar both call:
>
> handlers_dict.update({'associative': FooAssociativeQueryHandler})
> handlers_dict.update({'associative': BarAssociativeQueryHandler})
>
> What will happen?  If I am reading your code correctly, the last one
> wins.  If I need to use package foo and package bar (written by
> different folks possibly) in my own code, I can't.
>
> Am I understanding this correctly?  If so, I would consider this a bug.

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.


Ondrej

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

Reply via email to