I think sets would become less useful if they cannot contain symbolic expressions, e.g., Interval(a, b) instead of Interval(1, 2). So a strict type restriction is not helpful.
By the way, you should use isinstance, not "type(other) is Symbol" (and also don't use "is" to compare things unless you know there can only ever be exactly one of them). Aaron Meurer On Mon, Aug 4, 2014 at 7:27 AM, Samuel Lê <[email protected]> wrote: > Hi! > > I sent a fix to issue #7805 which is about forcing the method _contains of > an Interval to return False when the element is a Set (currently it's > throwing an exception). > My fix is just a check on the type of other in that method - if it's a > set, I return False. > > I was thinking, could we add for all the classes that inherit from Set a > list of types that can be contained? > For Interval, I would have to add in the __new__ method: > > self.containedTypes = [float, int] #and possibly other numerical types. > > Then, I could change my _contains method for any class implementing Set in > the following way: > > def _contains(self, other): > > if type(other) is not Symbol and not any(map(lambda t: > isinstance(other, t), self.containedTypes)): > return False > #do the actual calculations to see if other is contained, which will > depend on the class we are implementing > > That way, I automatically ensure that other will be of the types contained > by my Set, and I would be able to extend that to more complicated sets > (say, a set of sets...). > > Let me know what you think! > Sam > > > -- > You received this message because you are subscribed to the Google Groups > "sympy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/sympy. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sympy/1f2dabe5-3c42-4948-84e3-b2bee0ce5387%40googlegroups.com > <https://groups.google.com/d/msgid/sympy/1f2dabe5-3c42-4948-84e3-b2bee0ce5387%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sympy. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAKgW%3D6JZK-P%2BUr8z3TjZewyGc5hLv2jtFNdtKAu5cS56anPgRw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
