Issue #20189: Four additional builtin types
(PyTypeObject, PyMethodDescr_Type, _PyMethodWrapper_Type, and
PyWrapperDescr_Type) have been modified to provide introspection
information for builtins. Also: many additional Lib, test suite, and
Argument Clinic fixes.
Author: Larry Hastings <larry@hastings.org>
diff --git a/mock.py b/mock.py
index 46d0fcd..8ab2b7c 100644
--- a/mock.py
+++ b/mock.py
@@ -238,13 +238,27 @@
def _copy_func_details(func, funcopy):
funcopy.__name__ = func.__name__
funcopy.__doc__ = func.__doc__
- #funcopy.__dict__.update(func.__dict__)
- funcopy.__module__ = func.__module__
+ try:
+ funcopy.__text_signature__ = func.__text_signature__
+ except AttributeError:
+ pass
+ # we explicitly don't copy func.__dict__ into this copy as it would
+ # expose original attributes that should be mocked
+ try:
+ funcopy.__module__ = func.__module__
+ except AttributeError:
+ pass
+ try:
+ funcopy.__defaults__ = func.__defaults__
+ except AttributeError:
+ pass
+ try:
+ funcopy.__kwdefaults__ = func.__kwdefaults__
+ except AttributeError:
+ pass
if not inPy3k:
funcopy.func_defaults = func.func_defaults
return
- funcopy.__defaults__ = func.__defaults__
- funcopy.__kwdefaults__ = func.__kwdefaults__
def _callable(obj):