Commits

Ned Batchelder committed 16717e0

Now I can use collections.defaultdict

Comments (0)

Files changed (4)

     + set, sorted, reversed, rpartition
     + generator expressions
     + decorators
-    - collections.defaultdict
+    + collections.defaultdict
     + .startswith((,))
     - "with" statements
-
+    - .format() ?
 
 + Remove code only run on <2.6
 - Change data file to json

coverage/parser.py

 """Code parsing for Coverage."""
 
-import dis, re, sys, token, tokenize
+import collections, dis, re, sys, token, tokenize
 
 from coverage.backward import StringIO
 from coverage.backward import open_source, range    # pylint: disable=W0622
 
         """
         excluded_lines = self.first_lines(self.excluded)
-        exit_counts = {}
+        exit_counts = collections.defaultdict(int)
         for l1, l2 in self.arcs():
             if l1 < 0:
                 # Don't ever report -1 as a line number
             if l2 in excluded_lines:
                 # Arcs to excluded lines shouldn't count.
                 continue
-            if l1 not in exit_counts:
-                exit_counts[l1] = 0
             exit_counts[l1] += 1
 
         # Class definitions have one extra exit, so remove one for each:

coverage/results.py

 """Results of coverage measurement."""
 
+import collections
 import os
 
 from coverage.backward import iitems
         """
         missing = self.arcs_missing()
         branch_lines = set(self.branch_lines())
-        mba = {}
+        mba = collections.defaultdict(list)
         for l1, l2 in missing:
             if l1 in branch_lines:
-                if l1 not in mba:
-                    mba[l1] = []
                 mba[l1].append(l2)
         return mba
 

tests/coveragetest.py

 """Base test case class for coverage testing."""
 
 import glob, imp, os, random, shlex, shutil, sys, tempfile, textwrap
-import atexit
+import atexit, collections
 
 import coverage
 from coverage.backward import StringIO, to_bytes
             self.test_method_made_any_files = False
 
     # Map from class to info about how it ran.
-    class_behaviors = {}
+    class_behaviors = collections.defaultdict(ClassBehavior)
 
     @classmethod
     def report_on_class_behavior(cls):
 
     def class_behavior(self):
         """Get the ClassBehavior instance for this test."""
-        cls = self.__class__
-        if cls not in self.class_behaviors:
-            self.class_behaviors[cls] = self.ClassBehavior()
-        return self.class_behaviors[cls]
+        return self.class_behaviors[self.__class__]
 
 
 # When the process ends, find out about bad classes.
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.