Find Method Map in Bases Property

This property tells us that, if we are looking for some method in a class definition, but the method is not there, then we need to look in the base classes of the class

if the following are true:
  • value at class_name in map class_defs = class_def
  • value at "methods" in map class_def = methods_map
  • map methods_map contains key method_name = False

then definition of method method_name of class class_name in class_defs = definition of method method_name of base classes (value at "bases" in map class_def) in class_defs

Take a look at the following example:
Code Editor
LW Python State
Current Line1Current Tab0Time0
LW Python Simulator

The "Class Definitions" map is as follows:

[ entry "Animal": [ entry "bases": [ ], [ entry "methods": [ entry "__init__": [ entry "params": [ self, [ ] ], [ entry "line": 2, [ ] ] ], [ entry "move": [ entry "params": [ self, [ ] ], [ entry "line": 5, [ ] ] ], [ ] ] ], [ entry "line": 1, [ ] ] ] ], [ entry "Dog": [ entry "bases": [ "Animal", [ ] ], [ entry "methods": [ entry "jump": [ entry "params": [ self, [ ] ], [ entry "line": 8, [ ] ] ], [ ] ], [ entry "line": 7, [ ] ] ] ], [ ] ] ]

Here is a table view:

Class NameClass KeyValueMethod KeyValue
Animalline1
bases[ ]
methods__init__paramsself
line2
moveparamsself
line5
Dogline7
basesAnimal
methodsjumpparamsself
line8

There are 2 entries, 1 for the "Animal" class and another for the "Dog" class.

For conciseness, let's say that the above map is equal to the variable "class_defs."

This property has 3 conditions. First:

value at "Dog" in map class_defs = [ entry "bases": [ "Animal", [ ] ], [ entry "methods": [ entry "jump": [ entry "params": [ self, [ ] ], [ entry "line": 8, [ ] ] ], [ ] ], [ entry "line": 7, [ ] ] ] ]

And this is the second condition:

value at "methods" in map [ entry "bases": [ "Animal", [ ] ], [ entry "methods": [ entry "jump": [ entry "params": [ self, [ ] ], [ entry "line": 8, [ ] ] ], [ ] ], [ entry "line": 7, [ ] ] ] ] = [ entry "jump": [ entry "params": [ self, [ ] ], [ entry "line": 8, [ ] ] ], [ ] ]

The second condition says that the "methods" map of the "Dog" class is:

[ entry "jump": [ entry "params": [ self, [ ] ], [ entry "line": 8, [ ] ] ], [ ] ]

Finally, here is the third condition, which says that the "methods" map of the "Dog" class does not contain the key "__init__":

map [ entry "jump": [ entry "params": [ self, [ ] ], [ entry "line": 8, [ ] ] ], [ ] ] contains key "__init__" = False

Given the conditions above, we can conclude the following:

definition of method "__init__" of class "Dog" in class_defs = definition of method "__init__" of base classes (value at "bases" in map [ entry "bases": [ "Animal", [ ] ], [ entry "methods": [ entry "jump": [ entry "params": [ self, [ ] ], [ entry "line": 8, [ ] ] ], [ ] ], [ entry "line": 7, [ ] ] ] ]) in class_defs

This says that the "Dog" class' "__init__" definition is equal to the "__init__" definition in one of the base classes of "Dog."

If we look carefully, we can see that the "Dog" class has 1 base class, which is "Animal." Thus, the "Dog" class will use the "__init__" definition of the "Animal" class.


Comments

Please log in to add comments