> My initial reaction is that having such tricky behaviour is the wrong
interface choice, so I'd recommend that you revisit your choice with that
assumption and then see if you can convince yourself that you really do
need `A(a) is a` to be True.
OK, I found a different, simpler solution, as y
Many thanks, that was a very clear answer! I replaced properties by setter
methods now.
Unfortunately, I get strange doctest errors here (the doctesting framework
cannot find anything previously defined in the same docstring), so I can
only hope that I made no mistakes...
More tomorrow...
Ma
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)
On Saturday, March 28, 2015 at 2:02:19 AM UTC-7, Martin R wrote:
>
> Hi there!
>
> I need help with two questions for an interface (to the FindStat database)
> I'm writing on http://trac.sagemath.org/ticket/17818.
>
> a design question: it appears that, in sage, python properties are hardly
> use
On Sunday, March 29, 2015 at 9:35:25 AM UTC-7, Martin R wrote:
>
> What I'd like to achieve is that A(a) yields a, if a is an instance of A.
>
I think that means that A needs to be a factory function rather than a
normal class:
class Aclass(...):...
def A(a):
if isinstance(a,Aclass):
The easy answer: Make A a function that either instantiates Aclass (the
renamed class) or returns the argument unchanged.
The IMHO unhealthy alternative is to use a metaclass to change the way the
constructor works so that there is a magic classmethod called before the
constructor, and that mag
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