One function
_get_signature_object in testing-cabal/mock
The author described this change as “gh-102978: Fix mock.patch function signatures for class and staticmethod decorators (#103228)”. It counts as a record because the check below fails on the code as it stood at 1c7bfeff6 and passes on 079655cd9, with nothing else changed between the two runs.
Projecttesting-cabal/mock
Fix saved2023-04-16
Sharing licenceBSD-2-Clause · LICENSE.txt
Change size+6 −0
What the code was meant to do, written into the code itself as a docstring
Given an arbitrary, possibly callable object, try to create a suitable signature object. Return a (reduced func, signature) tuple, or None.
The change
| 9 | 9 | func = func.__init__ | |
| 10 | 10 | # Skip the `self` argument in __init__ | |
| 11 | 11 | eat_self = True | |
| 12 | + | elif isinstance(func, (classmethod, staticmethod)): | |
| 13 | + | if isinstance(func, classmethod): | |
| 14 | + | # Skip the `cls` argument of a class method | |
| 15 | + | eat_self = True | |
| 16 | + | # Use the original decorated method to extract the correct function signature | |
| 17 | + | func = func.__func__ | |
| 12 | 18 | elif not isinstance(func, FunctionTypes): | |
| 13 | 19 | # If we really want to model an instance of the passed type, | |
| 14 | 20 | # __call__ should be looked up, not __init__. |
The check that tells the two apart
fail→pass·mock/tests/testhelpers.py::SpecSignatureTest::test_autospec_signature_classmethod
Check file mock/tests/testhelpers.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.
Origin and history
The code before it1c7bfeff6575a5fee073bb648126780e00923936
Broken version dated2023-04-16
Modulemock.mock
Units changed_get_signature_object
Fingerprintfd28fbed176f0955
Checked2026-08-18 by goldset/0.1
Every field above is generated by our program. None of it is written by hand.
Other bugs found in testing-cabal/mock
- 2022-12-28create_autospec
- 2020-01-29_patch_dict
- 2020-01-29_patch_object
- 2012-01-22_Call
- 2011-07-19Fix callargs call comparisons
- 2011-07-13Fix bug where a failure to create a nested patch could leave patches undone