Skip to content

Commit

Permalink
Added some docstrings to _BareObject.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bystroushaak committed Sep 22, 2019
1 parent 41a436a commit 233312d
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/tinySelf/vm/object_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ def __init__(self, obj):
self.version = obj.map._version

def verify(self):
"""
Returns:
bool: True if versioned object is still valid.
"""
return self.obj.map._version == self.version


Expand Down Expand Up @@ -87,6 +91,15 @@ def set_slot(self, slot_name, value):
return True

def get_slot(self, slot_name):
"""
Get slot from this object only. See other methods for parent lookup.
Args:
slot_name (str):
Returns:
Object: Slot's content if found or None if not.
"""
if self._slot_values is None:
return None

Expand All @@ -105,7 +118,7 @@ def parent_lookup(self, slot_name):
slot_name (str): Name of the slot to look for.
Returns:
obj: Object instance or None if not found.
Object: Object instance or None if not found.
Raises:
KeyError: If multiple slots are found.
Expand Down Expand Up @@ -158,6 +171,14 @@ def parent_lookup(self, slot_name):
return result

def _store_to_parent_cache(self, slot_name, result, visited_as_list):
"""
Save slot and parent tree to the parent cache.
Args:
slot_name (str):
result (Object): Object to be cached.
visited_as_list (list): List of parents.
"""
if self.map._parent_cache is None:
self.map._parent_cache = LightWeightDictObjects()

Expand All @@ -167,6 +188,16 @@ def _store_to_parent_cache(self, slot_name, result, visited_as_list):
)

def _cached_lookup(self, slot_name):
"""
Look into cache and if the parent tree is still valid, return cached
value.
Args:
slot_name (str):
Returns:
Object: Instance of the object or None.
"""
if self.map._parent_cache is None:
return None

Expand Down

0 comments on commit 233312d

Please sign in to comment.