diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2014-11-23 07:30:07 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2014-11-23 07:30:07 -0500 |
commit | 737f8ffa024563fb8315f94cdf1484aa7bdb6eaa (patch) | |
tree | 4f509ac85244bdb4b251b1134257e0eadb020f62 /coverage/misc.py | |
parent | df5b3c800fdf4a2eef373196b1f0a166279a3566 (diff) | |
parent | d0a872c92e0e8c6ebb9530c2b61f2b9582612fb4 (diff) | |
download | python-coveragepy-737f8ffa024563fb8315f94cdf1484aa7bdb6eaa.tar.gz |
Merged pull request 43: --skip-covered
Diffstat (limited to 'coverage/misc.py')
-rw-r--r-- | coverage/misc.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/coverage/misc.py b/coverage/misc.py index f9a30bc..f0e043b 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 |