diff options
author | Berker Peksag <berker.peksag@gmail.com> | 2016-12-15 02:21:44 (GMT) |
---|---|---|
committer | Berker Peksag <berker.peksag@gmail.com> | 2016-12-15 02:21:44 (GMT) |
commit | 161a4dd495dbf5cb12364e8f6e2d113cfd0633fc (patch) | |
tree | 0cbcead70f90d4b9e2b53907a7f44609b1d93fb9 /Lib/unittest | |
parent | e660327cf10c51fc0e79e2c15224817c600cbded (diff) | |
download | cpython-161a4dd495dbf5cb12364e8f6e2d113cfd0633fc.zip cpython-161a4dd495dbf5cb12364e8f6e2d113cfd0633fc.tar.gz cpython-161a4dd495dbf5cb12364e8f6e2d113cfd0633fc.tar.bz2 |
Issue #28919: Simplify _copy_func_details() in unittest.mock
Patch by Jiajun Huang.
Diffstat (limited to 'Lib/unittest')
-rw-r--r-- | Lib/unittest/mock.py | 26 |
1 files changed, 8 insertions, 18 deletions
diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py index f134919..367c1e1 100644 --- a/Lib/unittest/mock.py +++ b/Lib/unittest/mock.py @@ -104,26 +104,16 @@ def _check_signature(func, mock, skipfirst, instance=False): def _copy_func_details(func, funcopy): - funcopy.__name__ = func.__name__ - funcopy.__doc__ = func.__doc__ - 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 + for attribute in ( + '__name__', '__doc__', '__text_signature__', + '__module__', '__defaults__', '__kwdefaults__', + ): + try: + setattr(funcopy, attribute, getattr(func, attribute)) + except AttributeError: + pass def _callable(obj): |