aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2014-11-01 12:53:44 -0400
committerJesse Luehrs <doy@tozt.net>2014-11-01 12:53:44 -0400
commitff4d379eafa094d1bbd969c9c3c5a5dfe7e2d492 (patch)
tree7aef591868e8fcaabe6d7a2363f8de64686b7f2a
parent497fa70441b145c3810b3bacc519fac4c2d94fd4 (diff)
downloadpython-mop-ff4d379eafa094d1bbd969c9c3c5a5dfe7e2d492.tar.gz
python-mop-ff4d379eafa094d1bbd969c9c3c5a5dfe7e2d492.zip
remove useless get_ prefixes
-rw-r--r--mop/__init__.py104
-rw-r--r--t/__init__.py8
-rw-r--r--t/database_test.py4
-rw-r--r--t/mop_test.py52
-rw-r--r--t/overrides_test.py34
5 files changed, 101 insertions, 101 deletions
diff --git a/mop/__init__.py b/mop/__init__.py
index 7d4f747..c35b206 100644
--- a/mop/__init__.py
+++ b/mop/__init__.py
@@ -24,7 +24,7 @@ def python_class_for(c, name=None):
key = c.__hash__()
if key not in UNDERLYING_CLASSES.keys():
if name is None:
- name = c.get_name()
+ name = c.name()
UNDERLYING_CLASSES[key] = type(name, (object,), {})
return UNDERLYING_CLASSES[key]
@@ -49,7 +49,7 @@ def bootstrap():
},
)
# need to make sure we call this explicitly with the class name during
- # the bootstrap, since we won't have get_name() yet
+ # the bootstrap, since we won't have name() yet
python_class_for(c, name)
return c
@@ -128,60 +128,60 @@ def bootstrap():
def gen_reader(name):
return lambda self: self.slots[name]
- # get_mro needs get_superclass
+ # mro needs superclass
Class.add_method(bootstrap_create_method(
- "get_superclass", gen_reader("superclass")
+ "superclass", gen_reader("superclass")
))
- # get_all_attributes requires get_mro
- def get_mro(self):
+ # all_attributes requires mro
+ def mro(self):
mro = [ self ]
- parent = self.get_superclass()
+ parent = self.superclass()
if parent:
- mro.extend(parent.get_mro())
+ mro.extend(parent.mro())
return mro
Class.add_method(bootstrap_create_method(
- "get_mro", get_mro
+ "mro", mro
))
- # get_all_attributes requires get_local_attributes
+ # all_attributes requires local_attributes
Class.add_method(bootstrap_create_method(
- "get_local_attributes", gen_reader("attributes")
+ "local_attributes", gen_reader("attributes")
))
- # create_instance requires get_all_attributes
- def get_all_attributes(self):
+ # create_instance requires all_attributes
+ def all_attributes(self):
attributes = {}
- for c in reversed(self.get_mro()):
- attributes.update(c.get_local_attributes())
+ for c in reversed(self.mro()):
+ attributes.update(c.local_attributes())
return attributes
Class.add_method(bootstrap_create_method(
- "get_all_attributes", get_all_attributes
+ "all_attributes", all_attributes
))
- # get_default_for_instance requires get_default
+ # default_for_instance requires default
Attribute.add_method(bootstrap_create_method(
- "get_default", gen_reader("default")
+ "default", gen_reader("default")
))
- # create_instance requires get_default_for_instance
- def get_default_for_instance(self):
- default = self.get_default()
+ # create_instance requires default_for_instance
+ def default_for_instance(self):
+ default = self.default()
if callable(default):
default = default()
return default
Attribute.add_method(bootstrap_create_method(
- "get_default_for_instance", get_default_for_instance
+ "default_for_instance", default_for_instance
))
- # set_value requires get_name
+ # set_value requires name
Attribute.add_method(bootstrap_create_method(
- "get_name", gen_reader("name")
+ "name", gen_reader("name")
))
# create_instance requires set_value
def set_value(self, instance, new_value):
- instance.slots[self.get_name()] = new_value
+ instance.slots[self.name()] = new_value
Attribute.add_method(bootstrap_create_method(
name="set_value", body=set_value
))
@@ -190,13 +190,13 @@ def bootstrap():
def create_instance(self, kwargs):
instance = BasicInstance(self, {})
instance.__class__ = python_class_for(self)
- attrs = self.get_all_attributes()
+ attrs = self.all_attributes()
for attr_name in attrs:
attr = attrs[attr_name]
if attr_name in kwargs.keys():
attr.set_value(instance, kwargs[attr_name])
else:
- attr.set_value(instance, attr.get_default_for_instance())
+ attr.set_value(instance, attr.default_for_instance())
return instance
Class.add_method(bootstrap_create_method(
"create_instance", create_instance
@@ -211,7 +211,7 @@ def bootstrap():
# Phase 5: Object construction works, just need attributes to construct with
def add_attribute(self, attr):
- self.get_local_attributes()[attr.get_name()] = attr
+ self.local_attributes()[attr.name()] = attr
Class.add_method(bootstrap_create_method(
"add_attribute", add_attribute
))
@@ -231,23 +231,23 @@ def bootstrap():
# Phase 6: now we can populate the rest of the mop
- def get_value(self, instance):
- return instance.slots[self.get_name()]
+ def value(self, instance):
+ return instance.slots[self.name()]
Attribute.add_method(Method.new(
- name="get_value", body=get_value
+ name="value", body=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)
+ return lambda self: self.metaclass.all_attributes()[name].value(self)
Method.add_method(Method.new(
- name="get_name", body=gen_reader("name")
+ name="name", body=gen_reader("name")
))
Method.add_method(Method.new(
- name="get_body", body=gen_reader("body")
+ name="body", body=gen_reader("body")
))
Class.add_attribute(Attribute.new(name="name"))
@@ -256,20 +256,20 @@ def bootstrap():
Class.add_attribute(Attribute.new(name="methods", default=lambda: {}))
Class.add_method(Method.new(
- name="get_name", body=gen_reader("name")
+ name="name", body=gen_reader("name")
))
Class.add_method(Method.new(
- name="get_local_methods", body=gen_reader("methods")
+ name="local_methods", body=gen_reader("methods")
))
- def get_all_methods(self):
+ def all_methods(self):
methods = {}
- for c in reversed(self.get_mro()):
- methods.update(c.get_local_methods())
+ for c in reversed(self.mro()):
+ methods.update(c.local_methods())
return methods
Class.add_method(Method.new(
- name="get_all_methods", body=get_all_methods
+ name="all_methods", body=all_methods
))
Class.add_method(Method.new(
@@ -283,21 +283,21 @@ def bootstrap():
))
def finalize(self):
- for method in self.get_all_methods().values():
- python_install_method(self, method.get_name(), method)
+ for method in self.all_methods().values():
+ python_install_method(self, method.name(), method)
Class.add_method(Method.new(
name="finalize", body=finalize
))
def isa(self, other):
- mro = self.metaclass.get_mro()
+ mro = self.metaclass.mro()
return other in mro
Object.add_method(Method.new(
name="isa", body=isa
))
def can(self, method_name):
- return self.metaclass.get_all_methods().get(method_name)
+ return self.metaclass.all_methods().get(method_name)
Object.add_method(Method.new(
name="can", body=can
))
@@ -305,7 +305,7 @@ def bootstrap():
# Phase 7: now we have to clean up after ourselves
def add_method(self, method):
- self.get_local_methods()[method.get_name()] = method
+ self.local_methods()[method.name()] = method
Class.add_method(Method.new(
name="add_method", body=add_method
))
@@ -316,15 +316,15 @@ def bootstrap():
# we can't call Method.finalize(), since that would overwrite our base
# implementation of Method.execute and lead to infinite recursion
- for method in Object.get_local_methods().values():
- python_install_method(Method, method.get_name(), method)
+ for method in Object.local_methods().values():
+ python_install_method(Method, method.name(), method)
# we add the better version of Method.execute to the internal method map,
# but we don't actually install it. this way, all method subclasses will
# use this implementation, but the base Method class will not (which is
# safe because we know exactly how the base Method class is implemented)
def execute(self, invocant, args, kwargs):
- body = self.metaclass.get_all_attributes()["body"].get_value(self)
+ body = self.metaclass.all_attributes()["body"].value(self)
return execute_method(body, invocant, args, kwargs)
Method.add_method(Method.new(
name="execute", body=execute
@@ -333,16 +333,16 @@ def bootstrap():
# do the same thing with accessor methods that we installed with our
# temporary version of gen_reader
Class.add_method(Method.new(
- name="get_superclass", body=gen_reader("superclass")
+ name="superclass", body=gen_reader("superclass")
))
Class.add_method(Method.new(
- name="get_local_attributes", body=gen_reader("attributes")
+ name="local_attributes", body=gen_reader("attributes")
))
Attribute.add_method(Method.new(
- name="get_default", body=gen_reader("default")
+ name="default", body=gen_reader("default")
))
Attribute.add_method(Method.new(
- name="get_name", body=gen_reader("name")
+ name="name", body=gen_reader("name")
))
bootstrap()
diff --git a/t/__init__.py b/t/__init__.py
index a714b9e..fdbb1aa 100644
--- a/t/__init__.py
+++ b/t/__init__.py
@@ -9,10 +9,10 @@ class InMemoryDatabase(object):
self.class_registry = {}
def register_class(self, c):
- self.class_registry[c.get_name()] = c
+ self.class_registry[c.name()] = c
def insert(self, name, obj):
- data = self._get_repr(obj)
+ data = self._repr(obj)
self.store[name] = json.dumps(
data,
separators=(',', ':'),
@@ -32,7 +32,7 @@ class InMemoryDatabase(object):
else:
raise Exception("object not in database")
- def _get_repr(self, obj):
+ def _repr(self, obj):
if type(obj) == type([]):
return { "type": "plain", "data": obj }
if type(obj) == type({}):
@@ -49,7 +49,7 @@ class InMemoryDatabase(object):
self.register_class(obj.metaclass)
return {
"type": "object",
- "class": obj.metaclass.get_name(),
+ "class": obj.metaclass.name(),
"data": obj.slots,
}
raise Exception("unknown object type")
diff --git a/t/database_test.py b/t/database_test.py
index bd278c2..696b649 100644
--- a/t/database_test.py
+++ b/t/database_test.py
@@ -32,11 +32,11 @@ class DatabaseTest(unittest.TestCase):
Point.add_attribute(Point.attribute_class().new(name="y"))
Point.add_method(Point.method_class().new(
name="x",
- body=lambda self: self.metaclass.get_all_attributes()["x"].get_value(self)
+ body=lambda self: self.metaclass.all_attributes()["x"].value(self)
))
Point.add_method(Point.method_class().new(
name="y",
- body=lambda self: self.metaclass.get_all_attributes()["y"].get_value(self)
+ body=lambda self: self.metaclass.all_attributes()["y"].value(self)
))
Point.finalize()
diff --git a/t/mop_test.py b/t/mop_test.py
index b511163..f48d041 100644
--- a/t/mop_test.py
+++ b/t/mop_test.py
@@ -19,28 +19,28 @@ class MopTest(unittest.TestCase):
assert mop.Object.isa(mop.Object)
assert mop.Object.isa(mop.Class)
- assert mop.Class.get_all_methods()["add_method"].isa(mop.Object)
- assert mop.Class.get_all_methods()["add_method"].isa(mop.Method)
- assert not mop.Class.get_all_methods()["add_method"].isa(mop.Class)
+ assert mop.Class.all_methods()["add_method"].isa(mop.Object)
+ assert mop.Class.all_methods()["add_method"].isa(mop.Method)
+ assert not mop.Class.all_methods()["add_method"].isa(mop.Class)
- assert mop.Class.get_all_attributes()["superclass"].isa(mop.Object)
- assert mop.Class.get_all_attributes()["superclass"].isa(mop.Attribute)
- assert not mop.Class.get_all_attributes()["superclass"].isa(mop.Class)
+ assert mop.Class.all_attributes()["superclass"].isa(mop.Object)
+ assert mop.Class.all_attributes()["superclass"].isa(mop.Attribute)
+ assert not mop.Class.all_attributes()["superclass"].isa(mop.Class)
- assert mop.Class.get_name() == "Class"
- assert mop.Object.get_name() == "Object"
- assert mop.Method.get_name() == "Method"
- assert mop.Attribute.get_name() == "Attribute"
+ assert mop.Class.name() == "Class"
+ assert mop.Object.name() == "Object"
+ assert mop.Method.name() == "Method"
+ assert mop.Attribute.name() == "Attribute"
- assert mop.Class.get_superclass() is mop.Object
- assert mop.Object.get_superclass() is None
- assert mop.Method.get_superclass() is mop.Object
- assert mop.Attribute.get_superclass() is mop.Object
+ assert mop.Class.superclass() is mop.Object
+ assert mop.Object.superclass() is None
+ assert mop.Method.superclass() is mop.Object
+ assert mop.Attribute.superclass() is mop.Object
- assert mop.Class.get_mro() == [ mop.Class, mop.Object ]
- assert mop.Object.get_mro() == [ mop.Object ]
- assert mop.Method.get_mro() == [ mop.Method, mop.Object ]
- assert mop.Attribute.get_mro() == [ mop.Attribute, mop.Object ]
+ assert mop.Class.mro() == [ mop.Class, mop.Object ]
+ assert mop.Object.mro() == [ mop.Object ]
+ assert mop.Method.mro() == [ mop.Method, mop.Object ]
+ assert mop.Attribute.mro() == [ mop.Attribute, mop.Object ]
def test_class_creation(self):
Point = mop.Class.new(
@@ -53,22 +53,22 @@ class MopTest(unittest.TestCase):
Point.add_method(Point.method_class().new(
name="x",
- body=lambda self: self.metaclass.get_all_attributes()["x"].get_value(self)
+ body=lambda self: self.metaclass.all_attributes()["x"].value(self)
))
Point.add_method(Point.method_class().new(
name="y",
- body=lambda self: self.metaclass.get_all_attributes()["y"].get_value(self)
+ body=lambda self: self.metaclass.all_attributes()["y"].value(self)
))
Point.add_method(Point.method_class().new(
name="set_x",
- body=lambda self, new_value: self.metaclass.get_all_attributes()["x"].set_value(self, new_value)
+ body=lambda self, new_value: self.metaclass.all_attributes()["x"].set_value(self, new_value)
))
Point.finalize()
assert Point.metaclass is mop.Class
assert Point.isa(mop.Object)
- assert Point.get_superclass() is mop.Object
- assert Point.get_mro() == [ Point, mop.Object ]
+ assert Point.superclass() is mop.Object
+ assert Point.mro() == [ Point, mop.Object ]
point = Point.new(x=1, y=2)
assert point.isa(Point)
@@ -92,14 +92,14 @@ class MopTest(unittest.TestCase):
Point3D.add_attribute(Point3D.attribute_class().new(name="z", default=0))
Point3D.add_method(Point3D.method_class().new(
name="z",
- body=lambda self: self.metaclass.get_all_attributes()["z"].get_value(self)
+ body=lambda self: self.metaclass.all_attributes()["z"].value(self)
))
Point3D.finalize()
assert Point3D.metaclass is mop.Class
assert Point3D.isa(mop.Object)
- assert Point3D.get_superclass() is Point
- assert Point3D.get_mro() == [ Point3D, Point, mop.Object ]
+ assert Point3D.superclass() is Point
+ assert Point3D.mro() == [ Point3D, Point, mop.Object ]
point3d = Point3D.new(x=3, y=4, z=5)
assert point3d.isa(Point3D)
diff --git a/t/overrides_test.py b/t/overrides_test.py
index dd20097..adf60b3 100644
--- a/t/overrides_test.py
+++ b/t/overrides_test.py
@@ -9,7 +9,7 @@ from . import InMemoryDatabase
# obscure the implementation and make it not as easy to follow (we would have
# to manage call stacks ourselves), and so we just do this instead for now
def call_method_at_class(c, method_name, invocant, *args, **kwargs):
- return c.get_all_methods()[method_name].slots["body"](
+ return c.all_methods()[method_name].slots["body"](
invocant, *args, **kwargs
)
@@ -20,11 +20,11 @@ class OverridesTest(unittest.TestCase):
superclass=mop.Class,
)
def add_attribute(self, attr):
- name = attr.get_name()
+ name = attr.name()
call_method_at_class(mop.Class, "add_attribute", self, attr)
self.add_method(self.method_class().new(
name=name,
- body=lambda self: self.metaclass.get_all_attributes()[name].get_value(self),
+ body=lambda self: self.metaclass.all_attributes()[name].value(self),
))
AccessorsMetaclass.add_method(AccessorsMetaclass.metaclass.method_class().new(
name="add_attribute",
@@ -53,7 +53,7 @@ class OverridesTest(unittest.TestCase):
)
def execute(self, invocant, args, kwargs):
- methods_called.append(self.get_name())
+ methods_called.append(self.name())
return call_method_at_class(mop.Method, "execute", self, invocant, args, kwargs)
TraceMethod.add_method(TraceMethod.metaclass.method_class().new(
name="execute",
@@ -79,11 +79,11 @@ class OverridesTest(unittest.TestCase):
Point.add_attribute(Point.attribute_class().new(name="y", default=0))
Point.add_method(Point.method_class().new(
name="x",
- body=lambda self: self.metaclass.get_all_attributes()["x"].get_value(self)
+ body=lambda self: self.metaclass.all_attributes()["x"].value(self)
))
Point.add_method(Point.method_class().new(
name="y",
- body=lambda self: self.metaclass.get_all_attributes()["y"].get_value(self)
+ body=lambda self: self.metaclass.all_attributes()["y"].value(self)
))
Point.finalize()
@@ -104,17 +104,17 @@ class OverridesTest(unittest.TestCase):
))
DatabaseAttribute.add_method(DatabaseAttribute.method_class().new(
name="db",
- body=lambda self: self.metaclass.get_all_attributes()["db"].get_value(self)
+ body=lambda self: self.metaclass.all_attributes()["db"].value(self)
))
- def get_value(self, instance):
- key = str(instance.__hash__()) + ":" + self.get_name()
+ def value(self, instance):
+ key = str(instance.__hash__()) + ":" + self.name()
return self.db().lookup(key)
DatabaseAttribute.add_method(DatabaseAttribute.method_class().new(
- name="get_value",
- body=get_value,
+ name="value",
+ body=value,
))
def set_value(self, instance, new_value):
- key = str(instance.__hash__()) + ":" + self.get_name()
+ key = str(instance.__hash__()) + ":" + self.name()
self.db().insert(key, new_value)
DatabaseAttribute.add_method(DatabaseAttribute.method_class().new(
name="set_value",
@@ -131,10 +131,10 @@ class OverridesTest(unittest.TestCase):
))
DatabaseBackedClass.add_method(DatabaseBackedClass.method_class().new(
name="db",
- body=lambda self: self.metaclass.get_all_attributes()["db"].get_value(self)
+ body=lambda self: self.metaclass.all_attributes()["db"].value(self)
))
def add_attribute(self, attr):
- attr.metaclass.get_all_attributes()["db"].set_value(attr, self.db())
+ attr.metaclass.all_attributes()["db"].set_value(attr, self.db())
call_method_at_class(mop.Class, "add_attribute", self, attr)
DatabaseBackedClass.add_method(DatabaseBackedClass.method_class().new(
name="add_attribute",
@@ -155,15 +155,15 @@ class OverridesTest(unittest.TestCase):
Point.add_attribute(Point.attribute_class().new(name="y", default=0))
Point.add_method(Point.method_class().new(
name="x",
- body=lambda self: self.metaclass.get_all_attributes()["x"].get_value(self)
+ body=lambda self: self.metaclass.all_attributes()["x"].value(self)
))
Point.add_method(Point.method_class().new(
name="y",
- body=lambda self: self.metaclass.get_all_attributes()["y"].get_value(self)
+ body=lambda self: self.metaclass.all_attributes()["y"].value(self)
))
Point.add_method(Point.method_class().new(
name="set_x",
- body=lambda self, new_value: self.metaclass.get_all_attributes()["x"].set_value(self, new_value)
+ body=lambda self, new_value: self.metaclass.all_attributes()["x"].set_value(self, new_value)
))
Point.finalize()