1.1 --- a/docs/concepts.txt Sat May 09 02:54:18 2009 +0200
1.2 +++ b/docs/concepts.txt Sat May 09 03:21:15 2009 +0200
1.3 @@ -234,17 +234,17 @@
1.4 Class C:
1.5
1.6 0 1 2 3 4 5 6 7 8
1.7 - classcode (unused) __new__ __new__ size class type attribute ...
1.8 - for C reference #args, reference reference
1.9 - defaults
1.10 + classcode (unused) __new__ __new__ funccode size class type attribute ...
1.11 + for C reference #args, for reference reference
1.12 + defaults instantiator
1.13 reference
1.14
1.15 Instance of C:
1.16
1.17 0 1 2 3 4 5 6 7 8
1.18 - classcode attrcode C.__call__ C.__call__ size class C attribute ...
1.19 - for C for C reference #args, reference reference
1.20 - (if exists) defaults
1.21 + classcode attrcode C.__call__ C.__call__ funccode size class C attribute ...
1.22 + for C for C reference #args, for reference reference
1.23 + (if exists) defaults C.__call__
1.24 reference
1.25
1.26 Function f:
2.1 --- a/micropython/__init__.py Sat May 09 02:54:18 2009 +0200
2.2 +++ b/micropython/__init__.py Sat May 09 03:21:15 2009 +0200
2.3 @@ -357,7 +357,7 @@
2.4 # entry for an instantiation function for the class.
2.5
2.6 elif isinstance(obj, micropython.inspect.Class):
2.7 - t.add(obj.full_name(), obj.get_instantiator().parameters())
2.8 + t.add(obj.get_instantiator().full_name(), obj.get_instantiator().parameters())
2.9
2.10 # Filter out all parameter table entries not referenced by keyword
2.11 # arguments.
3.1 --- a/micropython/data.py Sat May 09 02:54:18 2009 +0200
3.2 +++ b/micropython/data.py Sat May 09 03:21:15 2009 +0200
3.3 @@ -556,9 +556,12 @@
3.4
3.5 # Include a template of an instance for use when instantiating classes.
3.6
3.7 - call_method = self.get("__call__")
3.8 + call_method = self.all_class_attributes().get("__call__")
3.9 call_method_value = call_method and call_method.get_value()
3.10 call_method_code_location = call_method_value and call_method_value.code_location
3.11 + call_method_funccode = call_method_value and paramtable.as_list().get_code(call_method_value.full_name())
3.12 +
3.13 + instantiator_funccode = paramtable.as_list().get_code(self.get_instantiator().full_name())
3.14
3.15 # NOTE: The instantiator code is the first block of the class.
3.16
3.17 @@ -580,7 +583,8 @@
3.18 call_method_value and len(call_method_value.defaults)
3.19 ),
3.20 self.full_name(),
3.21 - len(self.instance_attributes()) + 1 # size
3.22 + len(self.instance_attributes()) + 1, # size
3.23 + call_method_funccode # funccode
3.24 ),
3.25
3.26 # Class...
3.27 @@ -594,7 +598,8 @@
3.28 len(self.get_instantiator().defaults)
3.29 ),
3.30 self.full_name(),
3.31 - len(self.class_attributes()) + 1 # size
3.32 + len(self.class_attributes()) + 1, # size
3.33 + instantiator_funccode # funccode
3.34 )
3.35 ]
3.36
3.37 @@ -639,7 +644,7 @@
3.38 "Return a function which can be used to instantiate the class."
3.39
3.40 if self.instantiator is None:
3.41 - self.instantiator = self.get_init_method().function_from_method()
3.42 + self.instantiator = self.get_init_method().as_instantiator()
3.43 return self.instantiator
3.44
3.45 def get_init_method(self):
3.46 @@ -974,7 +979,7 @@
3.47 ),
3.48 "__builtins__.function",
3.49 len(self.defaults) + 1, # size
3.50 - paramtable.as_list().get_code(self.full_name())
3.51 + paramtable.as_list().get_code(self.full_name()) # funccode
3.52 )
3.53 ]
3.54
3.55 @@ -1079,11 +1084,11 @@
3.56 self.all_local_usage = nparams + nothers
3.57 self.finalised = 1
3.58
3.59 - def function_from_method(self):
3.60 + def as_instantiator(self):
3.61
3.62 - "Make a function from a method."
3.63 + "Make an instantiator function from a method."
3.64
3.65 - function = Function(self.name + " (function)", self.parent, self.argnames[1:], self.defaults,
3.66 + function = Function(self.parent.name, self.parent.parent, self.argnames[1:], self.defaults,
3.67 self.has_star, self.has_dstar, self.module, self.astnode)
3.68 function.default_attrs = self.default_attrs
3.69 return function
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/tests/class_init_keywords.py Sat May 09 03:21:15 2009 +0200
4.3 @@ -0,0 +1,11 @@
4.4 +#!/usr/bin/env python
4.5 +
4.6 +class C:
4.7 + def __init__(self, x, y, z):
4.8 + self.x = x
4.9 + self.y = y
4.10 + self.z = z
4.11 +
4.12 +c = C(1, 2, z=3)
4.13 +
4.14 +# vim: tabstop=4 expandtab shiftwidth=4