[IronPython] Problem inheriting from C# abstract base class with overloaded constructors

Mark Traudt mtraudt at alum.mit.edu
Thu Dec 4 02:48:50 CET 2008

If I create an abstract base class in C# that has overloaded constructors,
and then subclass from this in IronPython, then I am unable to call the
non-default base class constructor from the __new__ method in the subclass. 
If I try, I get the result shown after the code sample.

Interestingly, if I change the base class to not be abstract and to have
public constructors (both changes are required) then my IronPython script
works fine.  

Is this a bug?  If not, then am I doing something wrong, or is this not
supported for some reason?

I reproduced this with IronPython-1.1.2 and IronPython-2.0B5.

*** OneOff.cs ***

namespace Test
             public abstract class Foo
		protected Foo()	

		protected Foo(int a)
			a_ = a; 

		public override string ToString()	
			return "Foo: " + a_;

		private int a_;

*** OneOff.py ***

import clr
from Test import *

class Bar(Foo):
   def __new__ (cls, a=0):
        return Foo.__new__(cls, a)

print Bar()
print Bar(42)

*** Results ***

Traceback (most recent call last):
  File C:\dev\OneOff\IronPython\OneOff.py, line 10, in
  File C:\dev\OneOff\IronPython\OneOff.py, line 8, in
  File , line 0, in DefaultNew##15
TypeError: default __new__ does not take parameters

View this message in context: http://www.nabble.com/Problem-inheriting-from-C--abstract-base-class-with-overloaded-constructors-tp20804327p20804327.html
Sent from the IronPython mailing list archive at Nabble.com.

More information about the Ironpython-users mailing list