python/cpython

Commits on Oct 11, 2020

  1. bpo-40423: Optimization: use close_range(2) if available (GH-22651)

    close_range(2) should be preferred at all times if it's available, otherwise we'll use closefrom(2) if available with a fallback to fdwalk(3) or plain old loop over fd range in order of most efficient to least.
    
    [note that this version does check for ENOSYS, but currently ignores all other errors]
    
    Automerge-Triggered-By: @pablogsal
  2. bpo-40422: create a common _Py_closerange API (GH-19754)

    Such an API can be used both for os.closerange and subprocess. For the latter, this yields potential improvement for platforms that have fdwalk but wouldn't have used it there. This will prove even more beneficial later for platforms that have close_range(2), as the new API will prefer that over all else if it's available.
    
    The new API is structured to look more like close_range(2), closing from [start, end] rather than the [low, high) of os.closerange().
    
    Automerge-Triggered-By: @gpshead
  3. bpo-41993: Fix possible issues in remove_module() (GH-22631)

    * PyMapping_HasKey() is not safe because it silences all exceptions and can return incorrect result.
    * Informative exceptions from PyMapping_DelItem() are overridden with RuntimeError and
      the original exception raised before calling remove_module() is lost.
    * There is a race condition between PyMapping_HasKey() and PyMapping_DelItem().

Commits on Oct 10, 2020

  1. bpo-42000: Cleanup the AST related C-code (GH-22641)

    - Use the proper asdl sequence when creating empty arguments
    - Remove reduntant casts (thanks to new typed asdl_sequences)
    - Remove MarshalPrototypeVisitor and some utilities from asdl generator
    - Fix the header of `Python/ast.c` (kept from pgen times)
    
    Automerge-Triggered-By: @pablogsal

Commits on Oct 9, 2020

Commits on Oct 8, 2020

  1. bpo-41306: Allow scale value to not be rounded (GH-21715)

    This fixes the test failure with Tk 6.8.10 which is caused by changes to how Tk rounds the `from`, `to` and `tickinterval` arguments. This PR uses `noconv` if the patchlevel is greater than or equal to 8.6.10 (credit to Serhiy for this idea as it is much simpler than what I previously proposed).
    
    Going into more detail for those who want it, the Tk change was made in [commit 591f68c](tcltk/tk@591f68c) and means that the arguments listed above are rounded relative to the value of `from`. However, when rounding the `from` argument ([line 623](https://github.com/tcltk/tk/blob/591f68cb382525b72664c6fecaab87742b6cc87a/generic/tkScale.c#L623)), it is rounded relative to itself (i.e. rounding `0`) and therefore the assigned value for `from` is always what is given (no matter what values of `from` and `resolution`).
    
    Automerge-Triggered-By: @pablogsal
  2. bpo-41376: Fix the documentation of `site.getusersitepackages()` (GH-…

    …21602)
    
    `site.getusersitepackages()` returns the location of the user-specific site-packages directory
    even when the user-specific site-packages is disabled.
    
    ```
    $ python -s -m site
    sys.path = [
        '/home/user/conda/lib/python37.zip',
        '/home/user/conda/lib/python3.7',
        '/home/user/conda/lib/python3.7/lib-dynload',
        '/home/user/conda/lib/python3.7/site-packages',
    ]
    USER_BASE: '/home/user/.local' (exists)
    USER_SITE: '/home/user/.local/lib/python3.7/site-packages' (doesn't exist)
    ENABLE_USER_SITE: False
    ```
    
    It was not practical to prevent the function from returning None if user-specific site-packages are disabled, since there are other uses of the function which are relying on this behaviour (e.g. `python -m site`).

Commits on Oct 7, 2020

Commits on Oct 6, 2020

  1. bpo-38605: Make 'from __future__ import annotations' the default (GH-…

    …20434)
    
    The hard part was making all the tests pass; there are some subtle issues here, because apparently the future import wasn't tested very thoroughly in previous Python versions.
    
    For example, `inspect.signature()` returned type objects normally (except for forward references), but strings with the future import. We changed it to try and return type objects by calling `typing.get_type_hints()`, but fall back on returning strings if that function fails (which it may do if there are future references in the annotations that require passing in a specific namespace to resolve).