diff options
Diffstat (limited to 'coverage')
-rw-r--r-- | coverage/control.py | 4 | ||||
-rw-r--r-- | coverage/misc.py | 24 | ||||
-rw-r--r-- | coverage/plugin.py | 23 |
3 files changed, 26 insertions, 25 deletions
diff --git a/coverage/control.py b/coverage/control.py index 1191b9eb..3e04bace 100644 --- a/coverage/control.py +++ b/coverage/control.py @@ -9,12 +9,12 @@ from coverage.collector import Collector from coverage.config import CoverageConfig from coverage.data import CoverageData from coverage.debug import DebugControl -from coverage.plugin import CoveragePlugin, Plugins, overrides +from coverage.plugin import CoveragePlugin, Plugins from coverage.files import FileLocator, TreeMatcher, FnmatchMatcher from coverage.files import PathAliases, find_python_files, prep_patterns from coverage.html import HtmlReporter from coverage.misc import CoverageException, bool_or_none, join_regex -from coverage.misc import file_be_gone +from coverage.misc import file_be_gone, overrides from coverage.results import Analysis, Numbers from coverage.summary import SummaryReporter from coverage.xmlreport import XmlReporter diff --git a/coverage/misc.py b/coverage/misc.py index f9a30bc5..f0e043b9 100644 --- a/coverage/misc.py +++ b/coverage/misc.py @@ -4,6 +4,7 @@ import errno import hashlib import inspect import os +import sys from coverage.backward import string_class, to_bytes @@ -135,6 +136,29 @@ class Hasher(object): return self.md5.hexdigest() +def overrides(obj, method_name, base_class): + """Does `obj` override the `method_name` it got from `base_class`? + + Determine if `obj` implements the method called `method_name`, which it + inherited from `base_class`. + + Returns a boolean. + + """ + klass = obj.__class__ + klass_func = getattr(klass, method_name) + base_func = getattr(base_class, method_name) + + # Python 2/3 compatibility: Python 2 returns an instancemethod object, the + # function is the .im_func attribute. Python 3 returns a plain function + # object already. + if sys.version_info < (3, 0): + klass_func = klass_func.im_func + base_func = base_func.im_func + + return klass_func is not base_func + + class CoverageException(Exception): """An exception specific to Coverage.""" pass diff --git a/coverage/plugin.py b/coverage/plugin.py index 3d41aab9..1e6e2353 100644 --- a/coverage/plugin.py +++ b/coverage/plugin.py @@ -129,26 +129,3 @@ class Plugins(object): def get(self, module): return self.names[module] - - -def overrides(obj, method_name, base_class): - """Does `obj` override the `method_name` it got from `base_class`? - - Determine if `obj` implements the method called `method_name`, which it - inherited from `base_class`. - - Returns a boolean. - - """ - klass = obj.__class__ - klass_func = getattr(klass, method_name) - base_func = getattr(base_class, method_name) - - # Python 2/3 compatibility: Python 2 returns an instancemethod object, the - # function is the .im_func attribute. Python 3 returns a plain function - # object already. - if sys.version_info < (3, 0): - klass_func = klass_func.im_func - base_func = base_func.im_func - - return klass_func is not base_func |