I have subclassed Symbol, like so:
class BaseScalar(Symbol):
"""
BaseScalar instances are used to express coordinate variables for field.
Not to be instantiated by the user.
"""
def __new__(cls, name, coord_sys, position, **assumptions):
if (position not in ['1', '2', '3']
and not isinstance(coord_sys, CoordSysRect)):
raise ValueError("Position of scalar not specified. \
See `position` in docstring of `BaseScalar`")
if name is None:
name = 'Dummy_' + str(Dummy._count)
obj = Symbol.__new__(cls, name, **assumptions)
obj.coord_sys = coord_sys
return obj
The problem is this:
An instance of this class is created with name 'x' (say). Fine. Everything
works as it should. Then, another instance of this class is created - again
with the name 'x'. The returned object is actually the same 'x' which was
made before. This is happening because __new__ of Symbol is cached - when
the new object is created, it returns the cached object from before.
What can I do for to generate a new instance of the class instead of
returning the already created object?
P.S.: If you are wondering why I am creating the objects with the same
name, it is because the objects are instantiated within another object. So,
it's perfectly alright.
--
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.
For more options, visit https://groups.google.com/groups/opt_out.