# HG changeset patch # User Paul Boddie # Date 1241832075 -7200 # Node ID 9cb85e5768fac0baf36a8f5e9430de4d38bffd9d # Parent 4db18d4b2a85bfe400af97b3b6896438e8076204 Added missing funccode to structures. Renamed function_from_method to as_instantiator with naming changes. Added a test of instantiation and keywords. diff -r 4db18d4b2a85 -r 9cb85e5768fa docs/concepts.txt --- a/docs/concepts.txt Sat May 09 02:54:18 2009 +0200 +++ b/docs/concepts.txt Sat May 09 03:21:15 2009 +0200 @@ -234,17 +234,17 @@ Class C: 0 1 2 3 4 5 6 7 8 - classcode (unused) __new__ __new__ size class type attribute ... - for C reference #args, reference reference - defaults + classcode (unused) __new__ __new__ funccode size class type attribute ... + for C reference #args, for reference reference + defaults instantiator reference Instance of C: 0 1 2 3 4 5 6 7 8 - classcode attrcode C.__call__ C.__call__ size class C attribute ... - for C for C reference #args, reference reference - (if exists) defaults + classcode attrcode C.__call__ C.__call__ funccode size class C attribute ... + for C for C reference #args, for reference reference + (if exists) defaults C.__call__ reference Function f: diff -r 4db18d4b2a85 -r 9cb85e5768fa micropython/__init__.py --- a/micropython/__init__.py Sat May 09 02:54:18 2009 +0200 +++ b/micropython/__init__.py Sat May 09 03:21:15 2009 +0200 @@ -357,7 +357,7 @@ # entry for an instantiation function for the class. elif isinstance(obj, micropython.inspect.Class): - t.add(obj.full_name(), obj.get_instantiator().parameters()) + t.add(obj.get_instantiator().full_name(), obj.get_instantiator().parameters()) # Filter out all parameter table entries not referenced by keyword # arguments. diff -r 4db18d4b2a85 -r 9cb85e5768fa micropython/data.py --- a/micropython/data.py Sat May 09 02:54:18 2009 +0200 +++ b/micropython/data.py Sat May 09 03:21:15 2009 +0200 @@ -556,9 +556,12 @@ # Include a template of an instance for use when instantiating classes. - call_method = self.get("__call__") + call_method = self.all_class_attributes().get("__call__") call_method_value = call_method and call_method.get_value() call_method_code_location = call_method_value and call_method_value.code_location + call_method_funccode = call_method_value and paramtable.as_list().get_code(call_method_value.full_name()) + + instantiator_funccode = paramtable.as_list().get_code(self.get_instantiator().full_name()) # NOTE: The instantiator code is the first block of the class. @@ -580,7 +583,8 @@ call_method_value and len(call_method_value.defaults) ), self.full_name(), - len(self.instance_attributes()) + 1 # size + len(self.instance_attributes()) + 1, # size + call_method_funccode # funccode ), # Class... @@ -594,7 +598,8 @@ len(self.get_instantiator().defaults) ), self.full_name(), - len(self.class_attributes()) + 1 # size + len(self.class_attributes()) + 1, # size + instantiator_funccode # funccode ) ] @@ -639,7 +644,7 @@ "Return a function which can be used to instantiate the class." if self.instantiator is None: - self.instantiator = self.get_init_method().function_from_method() + self.instantiator = self.get_init_method().as_instantiator() return self.instantiator def get_init_method(self): @@ -974,7 +979,7 @@ ), "__builtins__.function", len(self.defaults) + 1, # size - paramtable.as_list().get_code(self.full_name()) + paramtable.as_list().get_code(self.full_name()) # funccode ) ] @@ -1079,11 +1084,11 @@ self.all_local_usage = nparams + nothers self.finalised = 1 - def function_from_method(self): + def as_instantiator(self): - "Make a function from a method." + "Make an instantiator function from a method." - function = Function(self.name + " (function)", self.parent, self.argnames[1:], self.defaults, + function = Function(self.parent.name, self.parent.parent, self.argnames[1:], self.defaults, self.has_star, self.has_dstar, self.module, self.astnode) function.default_attrs = self.default_attrs return function diff -r 4db18d4b2a85 -r 9cb85e5768fa tests/class_init_keywords.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/class_init_keywords.py Sat May 09 03:21:15 2009 +0200 @@ -0,0 +1,11 @@ +#!/usr/bin/env python + +class C: + def __init__(self, x, y, z): + self.x = x + self.y = y + self.z = z + +c = C(1, 2, z=3) + +# vim: tabstop=4 expandtab shiftwidth=4