This is roughly what I had in mind: [Everything is fake here, to only thing that is supposed to be illustrated is how assumptions get cleared up when their objects vanish.]
import weakref class Assumption(object): pass class AssumePositive(Assumption): def __init__(self, x): self.var = weakref.ref(x, self.cb) def cb(self, var): if self.callback: self.callback(self) def __str__(self): return str(self.var) + ' > 0' class Symbol(object): def __init__(self, name): self.name = name def __str__(self): return str(self.name) assumptions = {} def remove_assumption(wr): print 'removing assumption', assumptions[wr] del assumptions[wr] N = 0 def assume(a): global N print 'adding assumption', a, 'as', N assumptions[a] = N a.callback = remove_assumption N += 1 def test2(): x = Symbol('y') assume(AssumePositive(x)) print assumptions print 'leaving test2' def test(): x = Symbol('x') assume(AssumePositive(x)) print assumptions print 'entering test2' test2() print assumptions print 'leaving test' test() -- You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to sympy@googlegroups.com. To unsubscribe from this group, send email to sympy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sympy?hl=en.