python/cpython

Permalink

  1. bpo-39511: PyThreadState_Clear() calls on_delete (GH-18296)

    PyThreadState.on_delete is a callback used to notify Python when a
    thread completes. _thread._set_sentinel() function creates a lock
    which is released when the thread completes. It sets on_delete
    callback to the internal release_sentinel() function. This lock is
    known as Threading._tstate_lock in the threading module.
    
    The release_sentinel() function uses the Python C API. The problem is
    that on_delete is called late in the Python finalization, when the C
    API is no longer fully working.
    
    The PyThreadState_Clear() function now calls the
    PyThreadState.on_delete callback. Previously, that happened in
    PyThreadState_Delete().
    
    The release_sentinel() function is now called when the C API is still
    fully working.
  1. bpo-38631: Replace Py_FatalError() with _PyObject_ASSERT_FAILED_MSG() (…

    …GH-18258)
    
    Replace Py_FatalError() with _PyObject_ASSERT_FAILED_MSG() in
    object.c and typeobject.c to also dump the involved Python object on
    a fatal error. It should ease debug when such fatal error occurs.
    
    If the double linked list is inconsistent, _Py_ForgetReference() no
    longer dumps previous and next objects in the fatal error, it now
    only dumps the current object. It ensures that the error message
    is displayed even if dumping the object does crash Python.
    
    Enhance _Py_ForgetReference() error messages;
    _PyObject_ASSERT_FAILED_MSG() logs the "_Py_ForgetReference" function
    name.
  1. Get mock coverage back to 100% (GH-18228)

    * use the `: pass` and `: yield` patterns for code that isn't expected to ever be executed.
    
    * The _Call items passed to _AnyComparer are only ever of length two, so assert instead of if/else
    
    * fix typo
    
    * Fix bug, where stop-without-start patching dict blows up with `TypeError: 'NoneType' object is not iterable`, highlighted by lack of coverage of an except branch.
    
    * The fix for bpo-37972 means _Call.count and _Call.index are no longer needed.
    
    * add coverage for calling next() on a mock_open with readline.return_value set.
    
    * __aiter__ is defined on the Mock so the one on _AsyncIterator is never called.
  2. bpo-39485: fix corner-case in method-detection of mock (GH-18252)

    Replace check for whether something is a method in the mock module. The
    previous version fails on PyPy, because there no method wrappers exist
    (everything looks like a regular Python-defined function). Thus the
    isinstance(getattr(result, '__get__', None), MethodWrapperTypes) check
    returns True for any descriptor, not just methods.
    
    This condition could also return erroneously True in CPython for
    C-defined descriptors.
    
    Instead to decide whether something is a method, just check directly
    whether it's a function defined on the class. This passes all tests on
    CPython and fixes the bug on PyPy.
  3. bpo-39153: Clarify C API *SetItem refcounting semantics (GH-18220)

    Some of the *SetItem methods in the C API steal a reference to the
    given value. This annotates the better behaved ones to assure the
    reader that these are not the ones with the inconsistent behaviour.
    
    * 📜🤖 Added by blurb_it.
    
    * make docs consistent with signature
    
    Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>