Hi Martin What about something like this:
class A(SageObject): def __new__(cls, a, b=None, c=None): if isinstance(a, A): print "just use a" return a else: print "create new instance" return super(A, cls).__new__(cls, a, b, c) def __init__(self, a, b=None, c=None): if isinstance(a, A): print "no init required" return print "init" Regards Jonas On 29.03.2015 18:35, 'Martin R' via sage-devel wrote:
Since the above appears to be a very difficult question (:-), I'm going to add another one - which is actually mentioned in the thread title, but I somehow forgot to ask... Suppose I have a class A with an __init__ method taking a single mandatory argument: class A(SageObject): def __init__(self, a, b=None, c=None): What I'd like to achieve is that A(a) yields a, if a is an instance of A. I have read a bit about unique representation and CachedRepresentation, etc., but what I really want to achieve here is, I hope, much simpler. I don't want to use CachedRepresentation, since the arguments of __init__ would be expensive to cache. Many thanks, Martin -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com <mailto:sage-devel+unsubscr...@googlegroups.com>. To post to this group, send email to sage-devel@googlegroups.com <mailto:sage-devel@googlegroups.com>. Visit this group at http://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
-- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at http://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.