Hi,

I *think* the reason why basic does not accept keyword arguments is that all arguments are stored in the tuple self.args, and when providing them by keyword they have no canonical order any more.

I think the best way to go is to do

class MyClass(Basic):
    def __new__(cls, arg1="foo", arg2="bar")
        return Basic.__new__(cls, arg1, arg2)

i.e. to manually provide a canonical argument order.

I don't think this should break anything - plenty of sympy objects provide their own __new__ (all relying on Basic.__new__ eventually, as far as I know).

Tom

On 06.06.2012 13:18, Sergiu Ivanov wrote:
Hello,

Consider the following code:

   class MyClass(Basic):
     def __init__(self, argument):
       print argument

I can create an instance of MyClass in this way:

   MyClass("something")

However, I cannot do

   MyClass(argument="something")

because of

   TypeError: __new__() got an unexpected keyword argument 'argument'

I don't really know much about the intricacies of Python inheritance,
but I can see that Basic.__new__ does indeed not accept any keyword
arguments and I think that may be the origin of my problem.

When I don't subclass Basic, both ways work nicely.

Now, I can achieve what I want by doing

   class MyClass(Basic):
     def __new__(cls, argument):
       print argument
       return Basic.__new__(cls)

I *think* this doesn't break anything, but could anyone confirm it?

Also, is there a serious reason to not have Basic accept keyword
arguments?  That's likely a noobistic question, so I beg your patience
to bear with me :-)

Sergiu


--
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.

Reply via email to