# HG changeset patch # User Paul Boddie # Date 1337383990 -7200 # Node ID faec8d7e1a16b702bd3869768db06c07085fef8b # Parent d5f5db3d3636326ec4e425eb768b713b5f2aa4f1 Print warnings via standard error. Added a test of for/if combinations and attribute usage. diff -r d5f5db3d3636 -r faec8d7e1a16 micropython/__init__.py --- a/micropython/__init__.py Fri May 18 01:21:20 2012 +0200 +++ b/micropython/__init__.py Sat May 19 01:33:10 2012 +0200 @@ -46,6 +46,7 @@ import micropython.table import bisect import os +#import sys try: set @@ -720,7 +721,7 @@ try: attr = objtable.access(objname, attrname) except TableError: - #print "Warning: object type %r does not support attribute %r" % (objname, attrname) + #print >>sys.stderr, "Warning: object type %r does not support attribute %r" % (objname, attrname) continue # Get the real identity of the attribute in order to diff -r d5f5db3d3636 -r faec8d7e1a16 micropython/common.py --- a/micropython/common.py Fri May 18 01:21:20 2012 +0200 +++ b/micropython/common.py Sat May 19 01:33:10 2012 +0200 @@ -20,6 +20,7 @@ """ import operator +import sys try: set @@ -358,11 +359,11 @@ attrnames = attrnames or () objtypes = objtable.all_possible_objects_plus_status(attrnames) if not objtypes: - print "Warning: usage in %r for %r finds no object supporting all attributes %r" % ( + print >>sys.stderr, "Warning: usage in %r for %r finds no object supporting all attributes %r" % ( unit_name, name, attrnames) objtypes = objtable.any_possible_objects_plus_status(attrnames) if not objtypes: - print "Warning: usage in %r for %r finds no object supporting any attributes %r" % ( + print >>sys.stderr, "Warning: usage in %r for %r finds no object supporting any attributes %r" % ( unit_name, name, attrnames) all_objtypes.update(objtypes) diff -r d5f5db3d3636 -r faec8d7e1a16 micropython/data.py --- a/micropython/data.py Fri May 18 01:21:20 2012 +0200 +++ b/micropython/data.py Sat May 19 01:33:10 2012 +0200 @@ -54,6 +54,7 @@ from micropython.program import ReplaceableContext, PlaceholderContext from micropython.common import * +import sys def shortrepr(obj): if obj is None: @@ -238,7 +239,7 @@ """ if value is None: - print "Warning: name %r in namespace %r has an unknown value (evaluated to None)." % (name, self.full_name()) + print >>sys.stderr, "Warning: name %r in namespace %r has an unknown value (evaluated to None)." % (name, self.full_name()) value = make_instance() if name in self.globals: @@ -1622,7 +1623,7 @@ self.allattr.update(self.all_class_attributes()) for name, attr in self.instance_attributes().items(): if self.allattr.has_key(name) and name != "__class__": - print "Warning: instance attribute %r in %r overrides class attribute." % (name, self) + print >>sys.stderr, "Warning: instance attribute %r in %r overrides class attribute." % (name, self) self.allattr[name] = attr return self.allattr diff -r d5f5db3d3636 -r faec8d7e1a16 micropython/inspect.py --- a/micropython/inspect.py Fri May 18 01:21:20 2012 +0200 +++ b/micropython/inspect.py Sat May 19 01:33:10 2012 +0200 @@ -75,6 +75,7 @@ from micropython.common import * from micropython.data import * import compiler.ast +import sys # Program visitors. @@ -672,7 +673,7 @@ elif isinstance(value, Module): self.store_module_attr(attrname, value) - print "Warning: attribute %r of module %r set outside the module." % (node.attrname, expr.get_value().name) + print >>sys.stderr, "Warning: attribute %r of module %r set outside the module." % (node.attrname, expr.get_value().name) elif isinstance(value, Class): self.store_class_attr(attrname, value) @@ -699,7 +700,7 @@ def visitAssName(self, node): if hasattr(node, "flags") and node.flags == "OP_DELETE": - print "Warning: deletion of attribute %r in %r is not supported." % (node.name, self.full_name()) + print >>sys.stderr, "Warning: deletion of attribute %r in %r is not supported." % (node.name, self.full_name()) #raise InspectError("Deletion of attribute %r is not supported." % node.name) self.store(node.name, self.expr) @@ -765,11 +766,11 @@ """ if self.namespaces: - print "Warning: class %r in %r is not global: ignored." % (node.name, self.namespaces[-1].full_name()) + print >>sys.stderr, "Warning: class %r in %r is not global: ignored." % (node.name, self.namespaces[-1].full_name()) return else: if self.in_loop: - print "Warning: class %r in %r defined in a loop." % (node.name, self.full_name()) + print >>sys.stderr, "Warning: class %r in %r defined in a loop." % (node.name, self.full_name()) cls = get_class(node.name, self.get_namespace(), self, node) @@ -933,7 +934,7 @@ module = self.importer.load(node.modname, 1) #if module is None: - # print "Warning:", node.modname, "not imported." + # print >>sys.stderr, "Warning:", node.modname, "not imported." for name, alias in node.names: if name != "*": diff -r d5f5db3d3636 -r faec8d7e1a16 micropython/report.py --- a/micropython/report.py Fri May 18 01:21:20 2012 +0200 +++ b/micropython/report.py Sat May 19 01:33:10 2012 +0200 @@ -565,7 +565,7 @@ bases = cls.bases self.stream.write("
\n" % cls.full_name()) else: - print "Warning: class %s not recognised!" % node.name + print >>sys.stderr, "Warning: class %s not recognised!" % node.name return # Write the declaration line. @@ -667,7 +667,7 @@ fn = node.unit self.stream.write("
\n" % fn.full_name()) else: - print "Warning: function %s not recognised!" % node.name + print >>sys.stderr, "Warning: function %s not recognised!" % node.name return # Write the declaration line. @@ -1070,7 +1070,7 @@ if hasattr(node, "unit"): fn = node.unit else: - print "Warning: function %s not recognised!" % node.name + print >>sys.stderr, "Warning: function %s not recognised!" % node.name return self._span_start("lambda") diff -r d5f5db3d3636 -r faec8d7e1a16 tests/for_if_usage.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/for_if_usage.py Sat May 19 01:33:10 2012 +0200 @@ -0,0 +1,18 @@ +#!/usr/bin/env python + +class C: + p = 1 + q = 2 + +c = C() +a = 1 + +for x in 0, 1, 2: + if a: + b = c.p + else: + b = c.q + +result_1 = b + +# vim: tabstop=4 expandtab shiftwidth=4