Have you tried? I assure you, you can create classes with constructors
which signature differs from the signature of the superclass constructor.

Anyway, even if you prefer to use `__new__`, you still need to pay
attention to the `args` attribute.

Also, keep in mind that what you are doing mixes together printing and
identification. Your objects are completely defined by the tuple
(coordinate_system, index). You do not need name. The name comes into play
only during pretty printing.

It would be much better if you just subclass Basic or Expr and keep only
the aforementioned tuple as args.

You can also look at `diffgeom`. It solves the exact problem that you have
for three different classes: BaseScalar, BaseVector and BaseForm.


On 25 July 2013 18:46, Prasoon Shukla <[email protected]> wrote:

> Okay. So, this is what happens if I use __init__:
>
> Symbol.__new__ is called. Here's the definition:
>
> def __new__(cls, name, **assumptions):
>        """Symbols are identified by name and assumptions::
>
> As you can see, the method expects 2 positional arguments and rest are
> keyword arguments (the assumptions). When I use __init__, the function call
> is something like this:
>
> def __init__(self, name, coord_sys, position, **assumptions):
>
> And that's the error.
>
> Now, even if I can use __init__, here's what will happen:
>
> Symbol.__new__ still gets called first. Inside Symbol.__new__, it makes
> this call:
> return Symbol.__xnew_cached_(cls, name, **assumptions)
>
> The method __xnew_cached is cached. So, if the symbol with the same name
> had already been defined, that gets returned instead of a new object.
> Therefore, we are back to our original problem - that symbol doesn't
> support any extra args. In fact, if we have a symbol, doing:
> >>> symbol.args
> returns an empty tuple.
>
>  --
> 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.
>
>
>

-- 
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.


Reply via email to