summaryrefslogtreecommitdiff
path: root/diffeq.py
diff options
context:
space:
mode:
authorJoe Anderson <jandew+dev@gmail.com>2011-11-13 14:40:52 -0600
committerJoe Anderson <jandew+dev@gmail.com>2011-11-13 14:40:52 -0600
commit0b83a5931534efeee7bf0f763a240e566d9cdfe2 (patch)
tree4a6640d4bfa6650cf7203afc159a224c40443ca1 /diffeq.py
parent5a2a5441bae50c7859b26dfc4c1550f8fb05cbf1 (diff)
parent92b01ef48a648324ef07aebacf062e55f392340e (diff)
downloadtoss-0b83a5931534efeee7bf0f763a240e566d9cdfe2.tar.gz
toss-0b83a5931534efeee7bf0f763a240e566d9cdfe2.zip
WIP on master: 5a2a544 forgot about this stash
Diffstat (limited to 'diffeq.py')
-rw-r--r--diffeq.py18
1 files changed, 15 insertions, 3 deletions
diff --git a/diffeq.py b/diffeq.py
index 05d42b6..3c8769c 100644
--- a/diffeq.py
+++ b/diffeq.py
@@ -10,18 +10,30 @@ class DiffEq(object):
>>> self._foo=2 #setting an _under var makes it still callable by...
>>> self.foo
2
+ >>> self.foo is self._foo
+ True #so they share the same namespace
>>> # Now suppose foo is a class method and bar is in _flags.
- >>> self.foo #finding the object having not found it before
+ >>> self.foo #finding the object having not found it before:
#self.foo() is called and stored to self.__foo
#self.__foo is returned
- >>> self.foo #finding the object having asked for it before
+ >>> self.foo #finding the object having asked for it before:
#self.__foo is returned
>>> self.bar=2 #setting bar resets all self.__foos
>>> self.foo #self.foo() is called again, self.__foo returned
+
+ >>> # You can also subvert the second mechanism using the first,
+ >>> # as the mechansims do not recurse on themselves.
+ >>> # Suppose _foo is a class method, bar is in _flags
+ >>> self.foo
+ <bound method self._foo of ... >
+ >>> self._foo
+ <bound method self._foo of ... >
+ >>> self
+ >>> # The class is prevented from creating ___trunder variables.
Note that with this behavior you should treat all variable names, be they
normal, _under, or __dunder, as in the same namespace. Don't even try to
@@ -59,7 +71,7 @@ class DiffEq(object):
sgetattr = super(DiffEq, self).__getattribute__
try:
value = sgetattr(attr)
- if type(value) == types.MethodType:
+ if type(value) == types.MethodType and attr[0] != '_':
try: value = sgetattr("__" + attr)
except AttributeError:
value = value()