mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
gh-102978: Fix mock.patch function signatures for class and staticmethod decorators (#103228)
Fixes unittest.mock.patch not enforcing function signatures for methods decorated with @classmethod or @staticmethod when patch is called with autospec=True.
This commit is contained in:
parent
19d2639d1e
commit
59e0de4903
5 changed files with 58 additions and 0 deletions
|
@ -98,6 +98,12 @@ def _get_signature_object(func, as_instance, eat_self):
|
|||
func = func.__init__
|
||||
# Skip the `self` argument in __init__
|
||||
eat_self = True
|
||||
elif isinstance(func, (classmethod, staticmethod)):
|
||||
if isinstance(func, classmethod):
|
||||
# Skip the `cls` argument of a class method
|
||||
eat_self = True
|
||||
# Use the original decorated method to extract the correct function signature
|
||||
func = func.__func__
|
||||
elif not isinstance(func, FunctionTypes):
|
||||
# If we really want to model an instance of the passed type,
|
||||
# __call__ should be looked up, not __init__.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue