UserSpace.add_bases#
- UserSpace.add_bases(*bases)[source]#
Add base spaces for inheritance.
Adds one or more
UserSpaceobjects as base spaces for this space. This space will inherit cells and references from the base spaces, following Python’s Method Resolution Order (MRO) for multiple inheritance.When base spaces are added:
Cells and references from base spaces are copied into this space
Inherited items can be overridden by defining them in this space
Multiple bases are resolved using C3 linearization
- Parameters:
*bases – One or more
UserSpaceobjects to use as bases. Can be passed as individual arguments:add_bases(base1, base2)
Example
>>> base1 = model.new_space('Base1') >>> base1.new_cells('calc', lambda x: x * 2) >>> base2 = model.new_space('Base2') >>> base2.new_cells('other', lambda x: x + 10) >>> derived = model.new_space('Derived') >>> derived.add_bases(base1, base2) >>> derived.calc(5) # Inherited from Base1 10 >>> derived.other(5) # Inherited from Base2 15
See also
remove_bases(): Remove base spacesbases: View current base spaces