mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
Issue #28919: Simplify _copy_func_details() in unittest.mock
Patch by Jiajun Huang.
This commit is contained in:
parent
e660327cf1
commit
161a4dd495
1 changed files with 8 additions and 18 deletions
|
@ -104,26 +104,16 @@ def _check_signature(func, mock, skipfirst, instance=False):
|
||||||
|
|
||||||
|
|
||||||
def _copy_func_details(func, funcopy):
|
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
|
# we explicitly don't copy func.__dict__ into this copy as it would
|
||||||
# expose original attributes that should be mocked
|
# expose original attributes that should be mocked
|
||||||
try:
|
for attribute in (
|
||||||
funcopy.__module__ = func.__module__
|
'__name__', '__doc__', '__text_signature__',
|
||||||
except AttributeError:
|
'__module__', '__defaults__', '__kwdefaults__',
|
||||||
pass
|
):
|
||||||
try:
|
try:
|
||||||
funcopy.__defaults__ = func.__defaults__
|
setattr(funcopy, attribute, getattr(func, attribute))
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
try:
|
|
||||||
funcopy.__kwdefaults__ = func.__kwdefaults__
|
|
||||||
except AttributeError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def _callable(obj):
|
def _callable(obj):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue