1.1 --- a/micropython/inspect.py Sat Apr 26 02:31:44 2008 +0200
1.2 +++ b/micropython/inspect.py Sat Apr 26 18:35:18 2008 +0200
1.3 @@ -773,6 +773,10 @@
1.4 self.constant_values = {}
1.5 self.constant_list = None # cache for constants
1.6
1.7 + # Keyword records.
1.8 +
1.9 + self.keyword_names = set()
1.10 +
1.11 # Image generation details.
1.12
1.13 self.location = None
1.14 @@ -821,7 +825,13 @@
1.15 capable of being used as an AST visitor.
1.16 """
1.17
1.18 - def __init__(self, name, importer=None):
1.19 + def __init__(self, name, importer):
1.20 +
1.21 + """
1.22 + Initialise this visitor with a module 'name' and an 'importer' which is
1.23 + used to provide access to other modules when required.
1.24 + """
1.25 +
1.26 ASTVisitor.__init__(self)
1.27 Module.__init__(self, name)
1.28 self.visitor = self
1.29 @@ -902,6 +912,9 @@
1.30 self.namespaces[-2].add_instance_attribute(name)
1.31
1.32 def get_parent(self):
1.33 +
1.34 + "Return the parent (or most recent) namespace currently exposed."
1.35 +
1.36 return (self.namespaces[-1:] or [self])[0]
1.37
1.38 # Visitor methods.
1.39 @@ -1038,10 +1051,6 @@
1.40 self.in_loop = 0
1.41
1.42 def visitFrom(self, node):
1.43 - if self.importer is None:
1.44 - raise InspectError(self.full_name(), node,
1.45 - "Please use the micropython.Importer class for code which uses the 'from' statement.")
1.46 -
1.47 module = self.importer.load(node.modname, 1)
1.48
1.49 #if module is None:
1.50 @@ -1152,10 +1161,6 @@
1.51 visitIfExp = NOP
1.52
1.53 def visitImport(self, node):
1.54 - if self.importer is None:
1.55 - raise InspectError(self.full_name(), node,
1.56 - "Please use the micropython.Importer class for code which uses the 'import' statement.")
1.57 -
1.58 for name, alias in node.names:
1.59 if alias is not None:
1.60 self.store(alias, self.importer.load(name, 1) or UnresolvedName(None, name, self))
1.61 @@ -1170,6 +1175,7 @@
1.62 self.dispatch(node.expr)
1.63 const = Const(node.name)
1.64 self.constant_values[node.name] = const
1.65 + self.keyword_names.add(node.name)
1.66 return None
1.67
1.68 visitLambda = NOP