# HG changeset patch # User Paul Boddie # Date 1282351558 -7200 # Node ID c8d581e85781eac01113132e317aaf0cb8d3f1d8 # Parent e872962185b5895274629ba0ef7505f173373341 Fixed importing to return cached package roots instead of leaves when requested. Added inspection support for augmented slice assignment. Fixed attribute vacuuming where lambdas (and other non-existent attributes) are being removed. Added convenience methods to UnresolvedName. Fixed various inflexible and incorrect cases in report generation. Fixed class attribute summaries where such attributes resolve to instances. Added various package import tests. diff -r e872962185b5 -r c8d581e85781 micropython/__init__.py --- a/micropython/__init__.py Fri Aug 20 01:43:51 2010 +0200 +++ b/micropython/__init__.py Sat Aug 21 02:45:58 2010 +0200 @@ -730,9 +730,15 @@ package exists. """ + if return_leaf: + name_for_return = name + else: + name_for_return = name.split(".")[0] + if self.modules.has_key(name) and self.modules[name].loaded: #print "Cached (%s)" % name - return self.modules[name] + return self.modules[name_for_return] + if self.verbose: print "Loading", name diff -r e872962185b5 -r c8d581e85781 micropython/data.py --- a/micropython/data.py Fri Aug 20 01:43:51 2010 +0200 +++ b/micropython/data.py Sat Aug 21 02:45:58 2010 +0200 @@ -143,7 +143,8 @@ return self.items() + self.lambdas.items() def vacuum_item(self, name): - del self[name] + if self.has_key(name): + del self[name] def add_lambda(self, obj): attr = Attr(None, self, obj.name) @@ -1317,7 +1318,7 @@ self.allattr.update(self.all_class_attributes()) for name, attr in self.instance_attributes().items(): if self.allattr.has_key(name): - print "Instance attribute %r in %r overrides class attribute." % (name, self) + print "Warning: instance attribute %r in %r overrides class attribute." % (name, self) self.allattr[name] = attr return self.allattr @@ -1603,11 +1604,14 @@ def add_descendant(self, cls): self.descendants.add(cls) - def all_class_attributes(self): + def all_attributes(self): return {} - def instance_attributes(self): - return {} + def all_attribute_names(self): + return [] + + all_class_attributes = class_attributes = instance_attributes = all_attributes + all_class_attribute_names = class_attribute_names = instance_attribute_names = all_attribute_names def __repr__(self): return "UnresolvedName(%r, %r)" % (self.name, self.parent_name) diff -r e872962185b5 -r c8d581e85781 micropython/inspect.py --- a/micropython/inspect.py Fri Aug 20 01:43:51 2010 +0200 +++ b/micropython/inspect.py Sat Aug 21 02:45:58 2010 +0200 @@ -573,14 +573,16 @@ self.expr = self.dispatch(node.expr) # NOTE: Similar to micropython.ast handler code. - # NOTE: Slices and subscripts not supported. + # NOTE: Slices and subscripts are supported by __setitem__(slice) and + # NOTE: not __setslice__. if isinstance(node.node, compiler.ast.Name): self.visitAssName(node.node) elif isinstance(node.node, compiler.ast.Getattr): self.visitAssAttr(node.node) else: - raise InspectError("AugAssign(Slice or Subscript)") + self.use_specific_attribute("__builtins__", "slice") + self.use_name("__setitem__", node) return None @@ -604,7 +606,7 @@ """ if self.namespaces: - print "Class %r in %r is not global: ignored." % (node.name, self.namespaces[-1].full_name()) + print "Warning: class %r in %r is not global: ignored." % (node.name, self.namespaces[-1].full_name()) return None else: if self.in_loop: diff -r e872962185b5 -r c8d581e85781 micropython/report.py --- a/micropython/report.py Fri Aug 20 01:43:51 2010 +0200 +++ b/micropython/report.py Sat Aug 21 02:45:58 2010 +0200 @@ -251,7 +251,7 @@ def _assname(self, name, node): self._span_start("assname") - if hasattr(node, "_attrnames") and node._attrnames[name]: + if hasattr(node, "_attrnames") and node._attrnames.get(name): attrnames = node._attrnames[name] self._name_start() self.stream.write(name) @@ -370,8 +370,8 @@ if attrs: for attr in attrs: - value = attr.get_value() - if value is not None: + if attr.is_strict_constant(): + value = attr.get_value() self.stream.write("" % self._attr(value.full_name())) self._object_name_ref(self.module, value, classes="summary-ref") self.stream.write("\n") @@ -534,7 +534,7 @@ self._name(node.modname) self._keyword("import", 1) first = 1 - for (name, alias), _name in map(None, node.names, node._names): + for name, alias in node.names: if not first: self.stream.write(", ") if alias: @@ -657,7 +657,8 @@ def visitRaise(self, node): self.stream.write("
\n") self._keyword("raise") - self.dispatch(node.expr1) + if node.expr1 is not None: + self.dispatch(node.expr1) if node.expr2 is not None: self.stream.write(",\n") self.dispatch(node.expr2) diff -r e872962185b5 -r c8d581e85781 tests/importer_package.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/importer_package.py Sat Aug 21 02:45:58 2010 +0200 @@ -0,0 +1,7 @@ +#!/usr/bin/env python + +import imported_package + +result_123 = imported_package.attribute + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r e872962185b5 -r c8d581e85781 tests/importer_package_local.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/importer_package_local.py Sat Aug 21 02:45:58 2010 +0200 @@ -0,0 +1,10 @@ +#!/usr/bin/env python + +import imported_package + +def f(): + return imported_package.attribute + +result_123 = f() + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r e872962185b5 -r c8d581e85781 tests/importer_package_module.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/importer_package_module.py Sat Aug 21 02:45:58 2010 +0200 @@ -0,0 +1,7 @@ +#!/usr/bin/env python + +import imported_package.module + +result_456 = imported_package.module.attribute + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r e872962185b5 -r c8d581e85781 tests/importer_package_module_local.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/importer_package_module_local.py Sat Aug 21 02:45:58 2010 +0200 @@ -0,0 +1,10 @@ +#!/usr/bin/env python + +import imported_package.module + +def f(): + return imported_package.module.attribute + +result_456 = f() + +# vim: tabstop=4 expandtab shiftwidth=4