bpo-29403: Fix mock's broken autospec behavior on method-bound builtin functions by habnabit · Pull Request #3 · python/cpython
Cython will, in the right circumstances, offer a MethodType instance where im_func is a builtin function. Any instance of MethodType is automatically assumed to be a python-defined function (more specifically, a function that has an inspectable signature), but _set_signature was still conservative in its assumptions. As a result _set_signature would return early with None instead of a mock since the im_func had no inspectable signature. This causes problems deeper inside mock, as _set_signature is assumed to _always_ return a mock, and nothing checked its return value. In similar corner cases, autospec will simply not check the spec of the function, so _set_signature is amended to now return early with the original, not-wrapped mock object.
wdxal
mentioned this pull request
This was referenced
Feb 11, 2025SonicField added a commit to SonicField/cpython that referenced this pull request
Jan 19, 2026Add timing for all intermediate GC phases to diagnose the 50-80ms gap between timed phases and total gc.collect() time. New timing fields: - scan_heap_ns: parallel scan_heap phase - disable_deferred_ns: disable deferred refcounting loop - find_weakrefs_ns: find_weakref_callbacks - stw1_ns: StartTheWorld python#1 - objs_decref_ns: cleanup_worklist(objs_to_decref) - weakref_callbacks_ns: call_weakref_callbacks - finalize_ns: finalize_garbage - stw2_ns: StopTheWorld python#2 - resurrection_ns: handle_resurrected_objects - freelists_ns: _PyGC_ClearAllFreeLists - clear_weakrefs_ns: clear_weakrefs - stw3_ns: StartTheWorld python#3 All values exposed via gc.get_parallel_stats()['phase_timing'].
Qanux
mentioned this pull request
ericvsmith pushed a commit to ericvsmith/cpython that referenced this pull request
Feb 24, 2026This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters