mirror of
https://github.com/python/cpython.git
synced 2025-11-09 10:01:42 +00:00
[3.11] gh-102978: Fix mock.patch function signatures for class and staticmethod decorators (GH-103228) (#103499)
Fixes unittest.mock.patch not enforcing function signatures for methods
decorated with @classmethod or @staticmethod when patch is called with
autospec=True.
(cherry picked from commit 59e0de4903)
Co-authored-by: Tomas R <tomas.roun8@gmail.com>
This commit is contained in:
parent
1692a16a25
commit
e95ca78fab
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