From 63132099a7e6e8c28923f8a28be4e34fa40891e0 Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Sun, 26 Jul 2015 17:43:51 -0700 Subject: [PATCH] wmltools: Use collections.defaultdict And minor nearby whitespace fixes. --- data/tools/wesnoth/wmltools.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/data/tools/wesnoth/wmltools.py b/data/tools/wesnoth/wmltools.py index 456fed1398a1..0351eeb940b9 100644 --- a/data/tools/wesnoth/wmltools.py +++ b/data/tools/wesnoth/wmltools.py @@ -3,6 +3,7 @@ """ +import collections import sys, os, re, sre_constants, hashlib, glob, gzip import string @@ -378,16 +379,17 @@ def __init__(self, namespace, filename, lineno=None, docstring=None, args=None): self.lineno = lineno self.docstring = docstring self.args = args - self.references = {} + self.references = collections.defaultdict(list) self.undef = None + def append(self, fn, n, a=None): - if fn not in self.references: - self.references[fn] = [] self.references[fn].append((n, a)) + def dump_references(self): "Dump all known references to this definition." for (file, refs) in self.references.items(): print " %s: %s" % (file, repr([x[0] for x in refs])[1:-1]) + def __cmp__(self, other): "Compare two documentation objects for place in the sort order." # Major sort by file, minor by line number. This presumes that the