I didn't test it extensively, but I think it should be enough to override the sort_key method
class Colored(Expr): def sort_key(self, order=None): return self.args[0].sort_key(order=order) Aaron Meurer On Thu, Mar 25, 2021 at 9:43 AM Paul Royik <distantjob...@gmail.com> wrote: > > Also, what is the best way to set a color? Setting color in args is not a > very good idea, as color is a string. > > On Thursday, March 25, 2021 at 4:06:42 PM UTC+2 Paul Royik wrote: >> >> I want to create a class that makes expression colored. >> class Colored(Expr): >> pass >> >> How do I make Colored behave exactly as its arg, when I sort args? >> >> (x+Colored(2)).as_ordered_terms() should give the same as >> (x+2).as_ordered_terms() >> (x*Colored(y)).as_ordered_factors() should give the same as >> (x*y).as_ordered_factors() >> Do I need to override some methods? > > -- > 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 sympy+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sympy/62a9ddd1-b7be-4821-94f7-37103518355en%40googlegroups.com. -- 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 sympy+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAKgW%3D6L3Z3Y_RzbbRYA2VMmxND-8k4CUvjZUHAFMnLg-8vRJ%2Bg%40mail.gmail.com.