aboutsummaryrefslogtreecommitdiffstats
path: root/setuptools/monkey.py
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2016-09-09 12:54:34 -0400
committerJason R. Coombs <jaraco@jaraco.com>2016-09-09 12:54:34 -0400
commit7756f651df47dc870e886c1b13c5b48068c2dd5b (patch)
tree95594c864b4df965a4206d174f186e7d3bcc14a5 /setuptools/monkey.py
parentb7b9cb23f217095e79c618c0e3196712d2d9a285 (diff)
downloadexternal_python_setuptools-7756f651df47dc870e886c1b13c5b48068c2dd5b.tar.gz
external_python_setuptools-7756f651df47dc870e886c1b13c5b48068c2dd5b.tar.bz2
external_python_setuptools-7756f651df47dc870e886c1b13c5b48068c2dd5b.zip
Allow get_unpatched to be called to get unpatched version of a class or function, further harmonizing the interfaces.
Diffstat (limited to 'setuptools/monkey.py')
-rw-r--r--setuptools/monkey.py14
1 files changed, 12 insertions, 2 deletions
diff --git a/setuptools/monkey.py b/setuptools/monkey.py
index 5f098986..7a23641c 100644
--- a/setuptools/monkey.py
+++ b/setuptools/monkey.py
@@ -5,6 +5,7 @@ Monkey patching of distutils.
import sys
import distutils.filelist
import platform
+import types
from .py26compat import import_module
@@ -18,7 +19,16 @@ if you think you need this functionality.
"""
-def get_unpatched(cls):
+def get_unpatched(item):
+ lookup = (
+ get_unpatched_class if isinstance(item, type) else
+ get_unpatched_function if isinstance(item, types.FunctionType) else
+ lambda item: None
+ )
+ return lookup(item)
+
+
+def get_unpatched_class(cls):
"""Protect against re-patching the distutils if reloaded
Also ensures that no other distutils extension monkeypatched the distutils
@@ -117,7 +127,7 @@ def patch_func(replacement, original):
setattr(target_mod, original.__name__, replacement)
-def get_unpatched_func(candidate):
+def get_unpatched_function(candidate):
return getattr(candidate, 'unpatched')