(original) (raw)

changeset: 105628:bbdfde7958a8 user: Berker Peksag berker.peksag@gmail.com date: Thu Dec 15 05:21:44 2016 +0300 files: Lib/unittest/mock.py description: Issue #28919: Simplify _copy_func_details() in unittest.mock Patch by Jiajun Huang. diff -r 0ff181ca7558 -r bbdfde7958a8 Lib/unittest/mock.py --- a/Lib/unittest/mock.py Wed Dec 14 20:37:53 2016 +0100 +++ b/Lib/unittest/mock.py Thu Dec 15 05:21:44 2016 +0300 @@ -104,26 +104,16 @@ 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): /berker.peksag@gmail.com