Skip to content

Commit 68b65ab

Browse files
Add code comments
1 parent 71c4c5b commit 68b65ab

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

aexpr/aexpr.py

+18
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import inspect
44

55
class ExpressionReaction:
6+
"""An Expression Reaction object will be called when a change is detected.
7+
Define the action with on_change(expression)."""
8+
69
def __init__(self, expression_to_monitor):
710
self.expression_to_monitor = expression_to_monitor
811
self.old_value = expression_to_monitor()
@@ -18,9 +21,16 @@ def call(self):
1821
self.old_value = new_value
1922

2023
class UnimplementedInstructionException(Exception):
24+
"""An UnimplementedInstructionException will be thrown when
25+
the analysis try to process an unknown byte-code."""
26+
2127
pass
2228

2329
class ObjectWrapper:
30+
"""Wraps an object on the object stack. Can be a placeholder,
31+
a buildin or a simple object. If it an attribute of another object,
32+
base_obj will contains the original object."""
33+
2434
def __init__(self, obj=None, base_obj=None, placeholder=False, buildin=False):
2535
self.obj = obj
2636
self.base_obj = base_obj
@@ -34,6 +44,9 @@ def is_build_in(self):
3444
return self.buildin
3545

3646
def placeaexpr(obj, attr_name, expression_reaction_object):
47+
"""placeaexpr will be called by the byte-code analysis
48+
when an instrumentable attribute is found."""
49+
3750
if not hasattr(obj, '__listenon__'):
3851
if not hasattr(type(obj), "__aexprhandler__"):
3952
original = type(obj).__setattr__
@@ -57,6 +70,11 @@ def execaexprhandler(self, name, value):
5770

5871

5972
def aexpr(lambda_expression, globalvars, localvars=None):
73+
"""aexpr performs the byte-code analysis to find all
74+
dependencies of the given expression. It places hooks on these dependencies.
75+
When one of these hooks is triggered, an ExpressionReaction will be executed.
76+
The method returns the ExpressionReaction which were created during this execution."""
77+
6078
expression_reaction_object = ExpressionReaction(lambda_expression)
6179

6280
#####

0 commit comments

Comments
 (0)