# HG changeset patch # User Paul Boddie # Date 1341768116 -7200 # Node ID f391131fd7c6504277eb0efddf08c0c4d547ebc7 # Parent 1f42e393ed152674d47a94eabb8aafdf6b20312f Removed duplication from type and attribute pop-up elements in reports. Added set compatibility imports. diff -r 1f42e393ed15 -r f391131fd7c6 micropython/common.py --- a/micropython/common.py Sun Jul 08 02:26:27 2012 +0200 +++ b/micropython/common.py Sun Jul 08 19:21:56 2012 +0200 @@ -23,6 +23,11 @@ from micropython.errors import * import sys +try: + set +except NameError: + from sets import Set as set + # Visitors and activities related to node annotations. class ASTVisitor: diff -r 1f42e393ed15 -r f391131fd7c6 micropython/program.py --- a/micropython/program.py Sun Jul 08 02:26:27 2012 +0200 +++ b/micropython/program.py Sun Jul 08 19:21:56 2012 +0200 @@ -19,6 +19,11 @@ this program. If not, see . """ +try: + set +except NameError: + from sets import Set as set + class Location: """ diff -r 1f42e393ed15 -r f391131fd7c6 micropython/report.py --- a/micropython/report.py Sun Jul 08 02:26:27 2012 +0200 +++ b/micropython/report.py Sun Jul 08 19:21:56 2012 +0200 @@ -370,7 +370,18 @@ def _attribute_start(self, attrname, attributes): if attributes: - attributes.sort(key=lambda t: t[2]) + + # Get the output form of the attributes. + + output = [] + for value, target, target_name in attributes: + if value and not isinstance(value, Instance): + fullname = value.full_name() + else: + fullname = target_name + "." + attrname + output.append((fullname, value)) + + output.sort() self._span_start("attr") self._popup_start("attributes-popup") @@ -380,22 +391,15 @@ # attributes. last = None - for value, target, target_name in attributes: - if value and not isinstance(value, Instance): - fullname = value.full_name() - current = (value, fullname) - if current != last: - if last is not None: - self.stream.write("
") + for fullname, value in output: + if fullname != last: + if last is not None: + self.stream.write("
") + if value is not None and not isinstance(value, Instance): self._object_name_ref(value.module, value, fullname, classes="attribute-name") - else: - fullname = target_name + "." + attrname - current = (None, fullname) - if current != last: - if last is not None: - self.stream.write("
") + else: self.stream.write(fullname) - last = current + last = fullname self._names_list_end() self._popup_end() @@ -984,8 +988,8 @@ def visitAssAttr(self, node): possible_types = self.possible_accessor_types(node, defining_users=0) - target_names = ["%s%s" % (is_static and "static " or "", target_name) - for target_name, is_static in possible_types] + target_names = set(["%s%s" % (is_static and "static " or "", target_name) + for target_name, is_static in possible_types]) attributes = self._get_attributes(possible_types, node.attrname) wraps_getattr = isinstance(node.expr, compiler.ast.Getattr) @@ -1084,8 +1088,8 @@ def visitGetattr(self, node): possible_types = self.possible_accessor_types(node, defining_users=0) - target_names = ["%s%s" % (is_static and "static " or "", target_name) - for target_name, is_static in possible_types] + target_names = set(["%s%s" % (is_static and "static " or "", target_name) + for target_name, is_static in possible_types]) attributes = self._get_attributes(possible_types, node.attrname) wraps_getattr = isinstance(node.expr, compiler.ast.Getattr)