1 | initial version |
A useful example of defining an inherited class is also given in the description of Sage's coercion model. The example shows a simple implementation of p-local integers as a class which inherits from Rings
. A crucial subtlety demonstrated there which I didn't see while skimming @benjaminfjones's reference is
You need to define a new __init__
method unless you want to use exactly the same one as the parent class.
In that __init__
method, you need to call the __init__
method of the parent class, and give self
as an argument. This is the only case I've come across where self
should be passed explicitly as an argument, and it took me a while to figure it out the first few times I tried to define a new class.