Commits

Ned Batchelder committed df2dddb

Get rid of our backward implementation of set, sorted, reversed, and rpartition.

Comments (0)

Files changed (15)

     - --branch = True ?
 
 - Remove 2.3, 2.4, 2.5 limitations
-    - set, sorted, reversed, rpartition
+    + set, sorted, reversed, rpartition
     - generator expressions
     - decorators
     - collections.defaultdict

coverage/backward.py

 
 import os, re, sys
 
-# Python 2.3 doesn't have `set`
-try:
-    set = set       # new in 2.4
-except NameError:
-    from sets import Set as set
-
-# Python 2.3 doesn't have `sorted`.
-try:
-    sorted = sorted
-except NameError:
-    def sorted(iterable):
-        """A 2.3-compatible implementation of `sorted`."""
-        lst = list(iterable)
-        lst.sort()
-        return lst
-
-# Python 2.3 doesn't have `reversed`.
-try:
-    reversed = reversed
-except NameError:
-    def reversed(iterable):
-        """A 2.3-compatible implementation of `reversed`."""
-        lst = list(iterable)
-        return lst[::-1]
-
-# rpartition is new in 2.5
-try:
-    "".rpartition
-except AttributeError:
-    def rpartition(s, sep):
-        """Implement s.rpartition(sep) for old Pythons."""
-        i = s.rfind(sep)
-        if i == -1:
-            return ('', '', s)
-        else:
-            return (s[:i], sep, s[i+len(sep):])
-else:
-    def rpartition(s, sep):
-        """A common interface for new Pythons."""
-        return s.rpartition(sep)
-
 # Pythons 2 and 3 differ on where to get StringIO
 try:
     from cStringIO import StringIO

coverage/cmdline.py

 
 import optparse, os, sys, traceback
 
-from coverage.backward import sorted                # pylint: disable=W0622
 from coverage.execfile import run_python_file, run_python_module
 from coverage.misc import CoverageException, ExceptionDuringRun, NoSource
 from coverage.debug import info_formatter

coverage/control.py

 import atexit, os, random, socket, sys
 
 from coverage.annotate import AnnotateReporter
-from coverage.backward import string_class, iitems, sorted  # pylint: disable=W0622
+from coverage.backward import string_class, iitems
 from coverage.codeunit import code_unit_factory, CodeUnit
 from coverage.collector import Collector
 from coverage.config import CoverageConfig
 
 import os
 
-from coverage.backward import iitems, pickle, sorted    # pylint: disable=W0622
+from coverage.backward import iitems, pickle
 from coverage.files import PathAliases
 from coverage.misc import file_be_gone
 
 import os
 import sys
 
-from coverage.backward import md5, sorted       # pylint: disable=W0622
+from coverage.backward import md5
 from coverage.backward import string_class, to_bytes
 
 

coverage/parser.py

 
 import dis, re, sys, token, tokenize
 
-from coverage.backward import set, sorted, StringIO # pylint: disable=W0622
+from coverage.backward import StringIO
 from coverage.backward import open_source, range    # pylint: disable=W0622
-from coverage.backward import reversed              # pylint: disable=W0622
 from coverage.backward import bytes_to_ints
 from coverage.bytecode import ByteCodes, CodeObjects
 from coverage.misc import nice_pair, expensive, join_regex

coverage/results.py

 
 import os
 
-from coverage.backward import iitems, set, sorted       # pylint: disable=W0622
+from coverage.backward import iitems
 from coverage.misc import format_lines, join_regex, NoSource
 from coverage.parser import CodeParser
 

coverage/xmlreport.py

 import xml.dom.minidom
 
 from coverage import __url__, __version__
-from coverage.backward import sorted, rpartition    # pylint: disable=W0622
 from coverage.report import Reporter
 
 def rate(hit, num):
 
         # Create the 'lines' and 'package' XML elements, which
         # are populated later.  Note that a package == a directory.
-        package_name = rpartition(cu.name, ".")[0]
+        package_name = cu.name.rpartition(".")[0]
         className = cu.name
 
         package = self.packages.setdefault(package_name, [{}, 0, 0, 0, 0])

tests/backunittest.py

 
 import difflib, re, sys, unittest
 
-from coverage.backward import set                   # pylint: disable=W0622
-
 
 def _need(method):
     """Do we need to define our own `method` method?"""

tests/coveragetest.py

 import atexit
 
 import coverage
-from coverage.backward import sorted, StringIO      # pylint: disable=W0622
-from coverage.backward import to_bytes
+from coverage.backward import StringIO, to_bytes
 from coverage.control import _TEST_NAME_FILE
 from tests.backtest import run_command
 from tests.backunittest import TestCase

tests/test_collector.py

 
 import coverage
 from coverage.backward import StringIO
-from coverage.backward import set                   # pylint: disable=W0622
 
 from tests.coveragetest import CoverageTest
 

tests/test_config.py

 # -*- coding: utf-8 -*-
 """Test the config file handling for coverage.py"""
 
-import sys
 import coverage
 from coverage.misc import CoverageException
 

tests/test_files.py

 
 from coverage.files import FileLocator, TreeMatcher, FnmatchMatcher
 from coverage.files import PathAliases, find_python_files, abs_file
-from coverage.backward import set                   # pylint: disable=W0622
 from coverage.misc import CoverageException
 
 from tests.coveragetest import CoverageTest

tests/test_testing.py

 """Tests that our test infrastructure is really working!"""
 
 import os, sys
-from coverage.backward import to_bytes, rpartition
+from coverage.backward import to_bytes
 from tests.backunittest import TestCase
 from tests.coveragetest import CoverageTest
 
-from coverage.backward import set                   # pylint: disable=W0622
 
 class TestingTest(TestCase):
     """Tests of helper methods on `backunittest.TestCase`."""
         executable = executable.split(":", 1)[1].strip()
         self.assertTrue(same_python_executable(executable, sys.executable))
         environ = [l for l in out if "COV_FOOBAR" in l][0]
-        _, _, environ = rpartition(environ, ":")
+        _, _, environ = environ.rpartition(":")
         self.assertEqual(environ.strip(), "COV_FOOBAR = XYZZY")