I think using __del__ is a bad idea.  See 
http://docs.python.org/reference/datamodel.html?highlight=__del__#object.__del__.
  Basically, __del__ is *not* called when you do "del x".  First off, "del x" 
reduces the reference count of x by 1, whereas x.__del__ is only called if the 
reference count reaches zero.  So if you do

a = [x]
del x

x.__del__ won't be called, because there is still a reference to x in b.  
Second, I think that __del__ is not guaranteed to happen immediately, but only 
at the next garbage collection event (I might be wrong here, though).  But I 
think that __del__ should only be used for cleanup magic that doesn't happen 
automatically with the regular garbage collector.  Implementing a feature like 
assumptions in it isn't what it was made for.

By the way, Ronan, Vinzent, Christian, and Tom, can you all add the ideas you 
have mentioned here as ideas on that wiki page?

Aaron Meurer

On Apr 30, 2011, at 8:25 AM, Tom Bachmann wrote:

> 
>>> 1. Make the new system at least as good as the old one. That is
>>> whenever I can write foo.is_bar I can write ask(foo, Q.bar) and I will
>>> get at least as good an answer.
>> 
>> I think the only problem could be that ask() is much slower for
>> trivial queries, needs to be verified. This should be not too hard to
>> fix though.
>> 
>>> In particular Symbol('x',
>>> positive=True) should register automatically in the global assumptions
>>> that x > 0 (if I understand correctly how the new system works...).
>> 
>> That is is not that easy, because this approach does not work with
>> global assumptions. Symbol('x', positive) only affects local symbols,
>> global assumptions affect *all* symbols.
>> 
>> In other words, you have to manually clean the global assumptions, so
>> this can't be used as a drop-in replacement for Symbol('x',
>> positive=True). Imagine running the test suite and global_assumptions
>> being spammed with hundreds of assumptions.
>> 
> 
> Couldn't symbol.__del__ just remove all global assumptions involving
> the about-to-be-deleted symbol? I suppose assumptions would have to
> store weak references for this to work.
> 
> Note: I come from a background of explicit memory allocation, so this
> might either not be feasible or not pythonic.
> 
>> A solution would be to implement local assumptions, imitating Python's
>> local scoping. I tried this approach some time ago, it is quite
>> hackish, but I got it working for Symbol(), but not really for
>> symbols() or var(). See my local_assump branch.
>> 
> 
> That would of course still be handy to have.
> 
>>> 2. Replace all queries foo.is_bar by ask(foo, Q.bar).
>> 
>> I we fix the two things I mentioned above, we could still have
>> foo.is_bar as a (maybe deprecated) shortcut.
>> 
>>> 3. Remove all implementations of the is_bar properties.
>>> 4. Remove all remaining remnants of the old system.
>> 
>> Vinzent
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sympy" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/sympy?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.

Reply via email to