aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2014-10-31 16:38:13 -0400
committerJesse Luehrs <doy@tozt.net>2014-10-31 16:38:13 -0400
commit27536fea937fc93b78a1dd0a3d5185eb42ae3573 (patch)
tree2d39eedac5b27cfba5847b3f42c4fb1939a27ddf
parentbdedc50524359fc0d5bc542695c8a85551ba449a (diff)
downloadpython-mop-27536fea937fc93b78a1dd0a3d5185eb42ae3573.tar.gz
python-mop-27536fea937fc93b78a1dd0a3d5185eb42ae3573.zip
use a better reader implementation for most things
it goes through the attribute protocol whenever possible
-rw-r--r--mop/__init__.py19
1 files changed, 13 insertions, 6 deletions
diff --git a/mop/__init__.py b/mop/__init__.py
index b2bf41c..dffa4f8 100644
--- a/mop/__init__.py
+++ b/mop/__init__.py
@@ -121,6 +121,7 @@ def bootstrap():
# Phase 4: manually assemble enough scaffolding to allow object construction
+ # temporary, we'll have a better version later
def gen_reader(name):
return lambda self: self.slots[name]
@@ -220,6 +221,18 @@ def bootstrap():
# Phase 6: now we can populate the rest of the mop
+ def get_value(self, instance):
+ return instance.slots[self.get_name()]
+ Attribute.add_method(Method.new(
+ name="get_value", body=get_value
+ ))
+
+ # here's the better implementation
+ # note that we can't replace the implementation of the methods implemented
+ # by the previous gen_reader because that would end up recursive
+ def gen_reader(name):
+ return lambda self: self.metaclass.get_all_attributes()[name].get_value(self)
+
Method.add_method(Method.new(
name="get_name", body=gen_reader("name")
))
@@ -227,12 +240,6 @@ def bootstrap():
name="get_body", body=gen_reader("body")
))
- def get_value(self, instance):
- return instance.slots[self.get_name()]
- Attribute.add_method(Method.new(
- name="get_value", body=get_value
- ))
-
Class.add_attribute(Attribute.new(name="name"))
Class.add_attribute(Attribute.new(name="superclass"))
Class.add_attribute(Attribute.new(name="attributes", default=lambda: {}))