1.1 --- a/micropython/__init__.py Sat Apr 26 02:31:44 2008 +0200
1.2 +++ b/micropython/__init__.py Sat Apr 26 18:35:18 2008 +0200
1.3 @@ -229,6 +229,9 @@
1.4
1.5 if self.paramtable is None:
1.6 t = self.paramtable = micropython.table.Table()
1.7 +
1.8 + # Visit each module, getting function and method details.
1.9 +
1.10 for module in self.get_modules():
1.11 for obj in module.all_objects:
1.12 if isinstance(obj, micropython.inspect.Function):
1.13 @@ -241,6 +244,21 @@
1.14 elif isinstance(obj, micropython.inspect.Class):
1.15 t.add(obj.full_name(), obj.get_instantiator().parameters())
1.16
1.17 + # Filter out all parameter table entries not referenced by keyword
1.18 + # arguments.
1.19 +
1.20 + keyword_names = set()
1.21 +
1.22 + for module in self.get_modules():
1.23 + keyword_names.update(module.keyword_names)
1.24 +
1.25 + for function_name, parameters in t.table.items():
1.26 + for name in parameters.keys():
1.27 + if name in keyword_names:
1.28 + break
1.29 + else:
1.30 + del t.table[function_name]
1.31 +
1.32 return self.paramtable
1.33
1.34 # Import methods.
2.1 --- a/micropython/inspect.py Sat Apr 26 02:31:44 2008 +0200
2.2 +++ b/micropython/inspect.py Sat Apr 26 18:35:18 2008 +0200
2.3 @@ -773,6 +773,10 @@
2.4 self.constant_values = {}
2.5 self.constant_list = None # cache for constants
2.6
2.7 + # Keyword records.
2.8 +
2.9 + self.keyword_names = set()
2.10 +
2.11 # Image generation details.
2.12
2.13 self.location = None
2.14 @@ -821,7 +825,13 @@
2.15 capable of being used as an AST visitor.
2.16 """
2.17
2.18 - def __init__(self, name, importer=None):
2.19 + def __init__(self, name, importer):
2.20 +
2.21 + """
2.22 + Initialise this visitor with a module 'name' and an 'importer' which is
2.23 + used to provide access to other modules when required.
2.24 + """
2.25 +
2.26 ASTVisitor.__init__(self)
2.27 Module.__init__(self, name)
2.28 self.visitor = self
2.29 @@ -902,6 +912,9 @@
2.30 self.namespaces[-2].add_instance_attribute(name)
2.31
2.32 def get_parent(self):
2.33 +
2.34 + "Return the parent (or most recent) namespace currently exposed."
2.35 +
2.36 return (self.namespaces[-1:] or [self])[0]
2.37
2.38 # Visitor methods.
2.39 @@ -1038,10 +1051,6 @@
2.40 self.in_loop = 0
2.41
2.42 def visitFrom(self, node):
2.43 - if self.importer is None:
2.44 - raise InspectError(self.full_name(), node,
2.45 - "Please use the micropython.Importer class for code which uses the 'from' statement.")
2.46 -
2.47 module = self.importer.load(node.modname, 1)
2.48
2.49 #if module is None:
2.50 @@ -1152,10 +1161,6 @@
2.51 visitIfExp = NOP
2.52
2.53 def visitImport(self, node):
2.54 - if self.importer is None:
2.55 - raise InspectError(self.full_name(), node,
2.56 - "Please use the micropython.Importer class for code which uses the 'import' statement.")
2.57 -
2.58 for name, alias in node.names:
2.59 if alias is not None:
2.60 self.store(alias, self.importer.load(name, 1) or UnresolvedName(None, name, self))
2.61 @@ -1170,6 +1175,7 @@
2.62 self.dispatch(node.expr)
2.63 const = Const(node.name)
2.64 self.constant_values[node.name] = const
2.65 + self.keyword_names.add(node.name)
2.66 return None
2.67
2.68 visitLambda = NOP