]> git.ipfire.org Git - thirdparty/Python/cpython.git/log
thirdparty/Python/cpython.git
4 years agobpo-42042: Use ids attribute instead of names attribute (GH-22739)
Dong-hee Na [Fri, 13 Nov 2020 15:15:17 +0000 (00:15 +0900)] 
bpo-42042: Use ids attribute instead of names attribute (GH-22739)

4 years agobpo-41617: Add _Py__has_builtin() macro (GH-23260)
Victor Stinner [Fri, 13 Nov 2020 14:38:17 +0000 (15:38 +0100)] 
bpo-41617: Add _Py__has_builtin() macro (GH-23260)

Fix building pycore_bitutils.h internal header on old clang version
without __builtin_bswap16() (ex: Xcode 4.6.3 on Mac OS X 10.7).

Add a new private _Py__has_builtin() macro to check for availability
of a preprocessor builtin function.

Co-Authored-By: Joshua Root <jmr@macports.org>
Co-authored-by: Joshua Root <jmr@macports.org>
4 years agobpo-42296: On Windows, fix CTRL+C regression (GH-23257)
Victor Stinner [Fri, 13 Nov 2020 13:44:42 +0000 (14:44 +0100)] 
bpo-42296: On Windows, fix CTRL+C regression (GH-23257)

On Windows, fix a regression in signal handling which prevented to
interrupt a program using CTRL+C. The signal handler can be run in a
thread different than the Python thread, in which case the test
deciding if the thread can handle signals is wrong.

On Windows, _PyEval_SignalReceived() now always sets eval_breaker to
1 since it cannot test _Py_ThreadCanHandleSignals(), and
  eval_frame_handle_pending() always calls
  _Py_ThreadCanHandleSignals() to recompute eval_breaker.

4 years agobpo-38823: Fix compiler warning in _ctypes on Windows (GH-23258)
Victor Stinner [Fri, 13 Nov 2020 13:44:11 +0000 (14:44 +0100)] 
bpo-38823: Fix compiler warning in _ctypes on Windows (GH-23258)

Explicitly cast PyExc_Exception to PyTypeObject* to fix the warning:

    modules\_ctypes\_ctypes.c(5748): warning C4133: '=':
    incompatible types - from 'PyObject *' to '_typeobject *'

4 years agobpo-42246: Fix memory leak in compiler (GH-23256)
Mark Shannon [Fri, 13 Nov 2020 12:53:53 +0000 (12:53 +0000)] 
bpo-42246: Fix memory leak in compiler (GH-23256)

* Fix potential memory leak in assembler init.

* Fix reference leak when encountering error during compilation of function body.

4 years agobpo-42246: Eliminate jumps to exit blocks by copying those blocks. (#23251)
Mark Shannon [Thu, 12 Nov 2020 19:49:33 +0000 (19:49 +0000)] 
bpo-42246: Eliminate jumps to exit blocks by copying those blocks. (#23251)

* Compiler: eliminate jumps to short exit blocks by copying.

4 years agobpo-42308: Add threading.__excepthook__ (GH-23218)
Mario Corchero [Thu, 12 Nov 2020 17:27:44 +0000 (18:27 +0100)] 
bpo-42308: Add threading.__excepthook__ (GH-23218)

Add threading.__excepthook__ to allow retrieving the original value
of threading.excepthook in case it is set to a broken or a different
value.

4 years agobpo-38823: Always build _ctypes with wchar_t (GH-23248)
Victor Stinner [Thu, 12 Nov 2020 14:38:13 +0000 (15:38 +0100)] 
bpo-38823: Always build _ctypes with wchar_t (GH-23248)

It is no longer possible to build the _ctypes extension module
without wchar_t type: remove CTYPES_UNICODE macro. Anyway, the
wchar_t type is required to build Python.

4 years agobpo-42260: Initialize time and warnings earlier at startup (GH-23249)
Victor Stinner [Thu, 12 Nov 2020 14:14:13 +0000 (15:14 +0100)] 
bpo-42260: Initialize time and warnings earlier at startup (GH-23249)

* Call _PyTime_Init() and _PyWarnings_InitState() earlier during the
  Python initialization.
* Inline _PyImportHooks_Init() into _PySys_InitCore().
* The _warnings initialization function no longer call
  _PyWarnings_InitState() to prevent resetting filters_version to 0.
* _PyWarnings_InitState() now returns an int and no longer clear the
  state in case of error (it's done anyway at Python exit).
* Rework init_importlib(), fix refleaks on errors.

4 years agobpo-38823: Fix refleaks in _ctypes extension init (GH-23247)
Victor Stinner [Thu, 12 Nov 2020 13:09:57 +0000 (14:09 +0100)] 
bpo-38823: Fix refleaks in _ctypes extension init (GH-23247)

Fix reference leaks in the error path of the initialization function
the _ctypes extension module: call Py_DECREF(mod) on error.

Change PyCFuncPtr_Type name from _ctypes.PyCFuncPtr to
_ctypes.CFuncPtr to be consistent with the name exposed in the
_ctypes namespace (_ctypes.CFuncPtr).

Split PyInit__ctypes() function into sub-functions and add macros for
readability.

4 years agoBump magic number. (GH-23245)
Mark Shannon [Thu, 12 Nov 2020 10:42:44 +0000 (10:42 +0000)] 
Bump magic number. (GH-23245)

4 years agobpo-42237: Fix os.sendfile() on illumos (GH-23154)
Jakub Stasiak [Thu, 12 Nov 2020 09:49:30 +0000 (10:49 +0100)] 
bpo-42237: Fix os.sendfile() on illumos (GH-23154)

4 years agobpo-42246: Partial implementation of PEP 626. (GH-23113)
Mark Shannon [Thu, 12 Nov 2020 09:43:29 +0000 (09:43 +0000)] 
bpo-42246: Partial implementation of PEP 626. (GH-23113)

* Implement new line number table format, as defined in PEP 626.

4 years agoFix memory leak introduced by GH-22780 (GH-23237)
Andrew Svetlov [Wed, 11 Nov 2020 15:48:53 +0000 (17:48 +0200)] 
Fix memory leak introduced by GH-22780 (GH-23237)

4 years agobpo-40170: Fix PyType_Ready() refleak on static type (GH-23236)
Victor Stinner [Wed, 11 Nov 2020 13:27:32 +0000 (14:27 +0100)] 
bpo-40170: Fix PyType_Ready() refleak on static type (GH-23236)

bpo-1635741, bpo-40170: When called on a static type with NULL
tp_base, PyType_Ready() no longer increments the reference count of
the PyBaseObject_Type ("object). PyTypeObject.tp_base is a strong
reference on a heap type, but it is borrowed reference on a static
type.

Fix 99 reference leaks at Python exit (showrefcount 18623 => 18524).

4 years agobpo-40932: Note security caveat of shlex.quote on Windows (GH-21502)
Ammar Askar [Wed, 11 Nov 2020 07:29:56 +0000 (02:29 -0500)] 
bpo-40932: Note security caveat of shlex.quote on Windows (GH-21502)

Added a note in the `subprocess` docs that recommend using `shlex.quote` without mentioning that this is only applicable to Unix.

Also added a warning straight into the `shlex` docs since it only says "for simple syntaxes resembling that of the Unix shell" and says using `quote` plugs the security hole without mentioning this important caveat.

4 years agobpo-39411: pyclbr rewrite on AST (#18103)
Batuhan Taskaya [Wed, 11 Nov 2020 07:14:12 +0000 (10:14 +0300)] 
bpo-39411: pyclbr rewrite on AST (#18103)

- Rewrite pyclbr using an AST processor
- Add is_async to the pyclbr.Function

4 years agobpo-1635741: Fix typo in PyModule_AddObjectRef() doc (GH-23234)
Victor Stinner [Wed, 11 Nov 2020 00:52:26 +0000 (01:52 +0100)] 
bpo-1635741: Fix typo in PyModule_AddObjectRef() doc (GH-23234)

It is similar to PyModule_AddObject(), not to itself.

4 years agobpo-42294: Grammar fixes in doc glossary strong/weak refs (GH-23227)
kj [Tue, 10 Nov 2020 23:56:55 +0000 (07:56 +0800)] 
bpo-42294: Grammar fixes in doc glossary strong/weak refs (GH-23227)

4 years agobpo-42140: Improve asyncio.wait function (GH-22938)
Diogo Dutra [Tue, 10 Nov 2020 22:12:52 +0000 (19:12 -0300)] 
bpo-42140: Improve asyncio.wait function (GH-22938)

# Improve asyncio.wait function

The original code creates the futures set two times.
We can create this set before, avoiding the second creation.

This new behaviour [breaks the aiokafka library](https://github.com/aio-libs/aiokafka/pull/672), because it gives an iterator to that function, so the second iteration become empty.

Automerge-Triggered-By: GH:1st1
4 years agobpo-41073: PyType_GetSlot() can now accept static types. (GH-21931)
Hai Shi [Tue, 10 Nov 2020 20:53:46 +0000 (04:53 +0800)] 
bpo-41073: PyType_GetSlot() can now accept static types. (GH-21931)

PyType_GetSlot() can now accept static types.

Co-Authored-By: Petr Viktorin <encukou@gmail.com>
Automerge-Triggered-By: GH:encukou
4 years agobpo-42260: Fix _PyConfig_Read() if compute_path_config=0 (GH-23220)
Victor Stinner [Tue, 10 Nov 2020 20:10:22 +0000 (21:10 +0100)] 
bpo-42260: Fix _PyConfig_Read() if compute_path_config=0 (GH-23220)

Fix _PyConfig_Read() if compute_path_config=0: use values set by
Py_SetPath(), Py_SetPythonHome() and Py_SetProgramName(). Add
compute_path_config parameter to _PyConfig_InitPathConfig().

The following functions now return NULL if called before
Py_Initialize():

* Py_GetExecPrefix()
* Py_GetPath()
* Py_GetPrefix()
* Py_GetProgramFullPath()
* Py_GetProgramName()
* Py_GetPythonHome()

These functions no longer automatically computes the Python Path
Configuration. Moreover, Py_SetPath() no longer computes
program_full_path.

4 years agobpo-42085: Introduce dedicated entry in PyAsyncMethods for sending values (#22780)
Vladimir Matveev [Tue, 10 Nov 2020 20:09:55 +0000 (12:09 -0800)] 
bpo-42085: Introduce dedicated entry in PyAsyncMethods for sending values (#22780)

4 years agobpo-42014: shutil.rmtree: call onerror with correct function (GH-22585)
Michal Čihař [Tue, 10 Nov 2020 16:06:02 +0000 (17:06 +0100)] 
bpo-42014: shutil.rmtree: call onerror with correct function (GH-22585)

The onerror is supposed to be called with failed function, but in this case lstat is wrongly used instead of open.

Not sure if this needs bug or not...

Automerge-Triggered-By: GH:hynek
4 years agoUpdate whatsnew for 3.10 release about addition of contextlib.aclosing (GH-23217)
Joongi Kim [Tue, 10 Nov 2020 15:19:11 +0000 (00:19 +0900)] 
Update whatsnew for 3.10 release about addition of contextlib.aclosing (GH-23217)

4 years agobpo-42183: Fix a stack overflow error for asyncio Task or Future repr() (GH-23020)
Andrew Svetlov [Tue, 10 Nov 2020 13:58:31 +0000 (15:58 +0200)] 
bpo-42183: Fix a stack overflow error for asyncio Task or Future repr() (GH-23020)

The overflow occurs under some circumstances when a task or future
recursively returns itself.

Co-authored-by: Kyle Stanley <aeros167@gmail.com>
4 years agobpo-42171: Add PEP573-related items to the limited API (GH-23009)
Petr Viktorin [Tue, 10 Nov 2020 13:47:31 +0000 (14:47 +0100)] 
bpo-42171: Add PEP573-related items to the limited API (GH-23009)

4 years agoFix typo in test_array.py (GH-23189)
Ikko Ashimine [Tue, 10 Nov 2020 12:42:36 +0000 (21:42 +0900)] 
Fix typo in test_array.py (GH-23189)

4 years agobpo-42260: Compute the path config in the main init (GH-23211)
Victor Stinner [Tue, 10 Nov 2020 12:21:52 +0000 (13:21 +0100)] 
bpo-42260: Compute the path config in the main init (GH-23211)

The path configuration is now computed in the "main" initialization.
The core initialization no longer computes it.

* Add _PyConfig_Read() function to read the configuration without
  computing the path configuration.
* pyinit_core() no longer computes the path configuration: it is now
  computed by init_interp_main().
* The path configuration output members of PyConfig are now optional:

  * executable
  * base_executable
  * prefix
  * base_prefix
  * exec_prefix
  * base_exec_prefix

* _PySys_UpdateConfig() now skips NULL strings in PyConfig.
* _testembed: Rename test_set_config() to test_init_set_config() for
  consistency with other tests.

4 years agoFix typo in unicodeobject.c (GH-23180)
Ikko Ashimine [Tue, 10 Nov 2020 05:57:34 +0000 (14:57 +0900)] 
Fix typo in unicodeobject.c (GH-23180)

exeeds -> exceeds

Automerge-Triggered-By: GH:Mariatta
5 years agobpo-36310: Allow pygettext.py to detect calls to gettext in f-strings. (GH-19875)
jack1142 [Mon, 9 Nov 2020 22:50:45 +0000 (23:50 +0100)] 
bpo-36310: Allow pygettext.py to detect calls to gettext in f-strings. (GH-19875)

Adds support to Tools/i18n/pygettext.py for gettext calls in f-strings. This process is done by parsing the f-strings, processing each value, and flagging the ones which contain a gettext call.

Co-authored-by: Batuhan Taskaya <batuhanosmantaskaya@gmail.com>
5 years agobpo-41712: Avoid runaway regex match in upload scripts (GH-23166)
Yash Shete [Mon, 9 Nov 2020 17:38:09 +0000 (23:08 +0530)] 
bpo-41712: Avoid runaway regex match in upload scripts (GH-23166)

5 years agobpo-42294: Add borrowed/strong reference to doc glossary (GH-23206)
Victor Stinner [Mon, 9 Nov 2020 12:40:47 +0000 (13:40 +0100)] 
bpo-42294: Add borrowed/strong reference to doc glossary (GH-23206)

Add "borrowed reference" and "strong reference" to the documentation
glossary.

Enhance also Py_INCREF() and Py_NewRef() documentation.

5 years agobpo-41543: contextlib.nullcontext can fill in for an async context manager (GH-21870)
Tom Gringauz [Mon, 9 Nov 2020 12:34:07 +0000 (14:34 +0200)] 
bpo-41543: contextlib.nullcontext can fill in for an async context manager (GH-21870)

Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
5 years agobpo-40624: Add support for the XPath != operator in xml.etree (GH-22147)
Ammar Askar [Mon, 9 Nov 2020 07:02:39 +0000 (02:02 -0500)] 
bpo-40624: Add support for the XPath != operator in xml.etree (GH-22147)

5 years agobpo-42233: Add union type expression support for GenericAlias and fix de-duplicating...
kj [Mon, 9 Nov 2020 04:00:13 +0000 (12:00 +0800)] 
bpo-42233: Add union type expression support for GenericAlias and fix de-duplicating of GenericAlias (GH-23077)

5 years agobpo-41754: Ignore NotADirectoryError in invocation of xdg-settings (GH-23075)
Ronald Oussoren [Sun, 8 Nov 2020 09:46:55 +0000 (10:46 +0100)] 
bpo-41754: Ignore NotADirectoryError in invocation of xdg-settings (GH-23075)

It is not clear why this can happen, but several users have mentioned
getting this exception on macOS.

5 years agobpo-41100: Support macOS 11 and Apple Silicon (GH-22855)
Ronald Oussoren [Sun, 8 Nov 2020 09:05:27 +0000 (10:05 +0100)] 
bpo-41100: Support macOS 11 and Apple Silicon (GH-22855)

Co-authored-by: Lawrence D’Anna <lawrence_danna@apple.com>
* Add support for macOS 11 and Apple Silicon (aka arm64)

  As a side effect of this work use the system copy of libffi on macOS, and remove the vendored copy

* Support building on recent versions of macOS while deploying to older versions

  This allows building installers on macOS 11 while still supporting macOS 10.9.

5 years agoMinor wording change in concurrent.futures. (GH-23194)
Don Kirkby [Sun, 8 Nov 2020 09:01:23 +0000 (01:01 -0800)] 
Minor wording change in concurrent.futures. (GH-23194)

Fixes a grammar problem by adding a missing "as", and clarifies the wording of the valid ranges for max_workers.

5 years agobpo-40077: Convert _queuemodule to use heap types (GH-23136)
Erlend Egeberg Aasland [Sat, 7 Nov 2020 19:18:37 +0000 (20:18 +0100)] 
bpo-40077: Convert _queuemodule to use heap types (GH-23136)

@vstinner / @corona10, would you mind reviewing this?

5 years agobpo-42282: Fold constants inside named expressions (GH-23190)
Nick Coghlan [Sat, 7 Nov 2020 12:35:17 +0000 (22:35 +1000)] 
bpo-42282: Fold constants inside named expressions (GH-23190)

* The AST optimiser wasn't descending into named expressions, so
  any constant subexpressions weren't being folded at compile time
* Remove "default:" clauses inside the AST optimiser code to reduce the
  risk of similar bugs passing unnoticed in future compiler changes

5 years agobpo-41028: Doc: Move switchers to docsbuild-scripts. (GH-20969)
Julien Palard [Sat, 7 Nov 2020 11:28:31 +0000 (12:28 +0100)] 
bpo-41028: Doc: Move switchers to docsbuild-scripts. (GH-20969)

5 years agobpo-42133: update parts of the stdlib to fall back to `__spec__.loader` when `__loade...
Brett Cannon [Sat, 7 Nov 2020 02:45:56 +0000 (18:45 -0800)] 
bpo-42133: update parts of the stdlib to fall back to `__spec__.loader` when `__loader__` is missing (#22929)

5 years agoRemove outdated reference to pywin32 from platform module (GH-22005)
Andre Delfino [Fri, 6 Nov 2020 18:58:14 +0000 (15:58 -0300)] 
Remove outdated reference to pywin32 from platform module (GH-22005)

5 years agobpo-41832: PyType_FromModuleAndSpec() now accepts NULL tp_doc (GH-23123)
Hai Shi [Fri, 6 Nov 2020 16:04:47 +0000 (00:04 +0800)] 
bpo-41832: PyType_FromModuleAndSpec() now accepts NULL tp_doc (GH-23123)

5 years agoMinor grammar edits for the descriptor howto guide (GH-#23175)
Raymond Hettinger [Fri, 6 Nov 2020 09:30:17 +0000 (01:30 -0800)] 
Minor grammar edits for the descriptor howto guide (GH-#23175)

5 years agobpo-42179: Doc/tutorial: Remove mention of __cause__ (GH-23162)
Inada Naoki [Fri, 6 Nov 2020 02:45:01 +0000 (11:45 +0900)] 
bpo-42179: Doc/tutorial: Remove mention of __cause__ (GH-23162)

5 years agobpo-26389: Allow passing an exception object in the traceback module (GH-22610)
Zackery Spytz [Thu, 5 Nov 2020 22:18:44 +0000 (15:18 -0700)] 
bpo-26389: Allow passing an exception object in the traceback module (GH-22610)

The format_exception(), format_exception_only(), and
print_exception() functions can now take an exception object as a positional-only argument.

Co-Authored-By: Matthias Bussonnier <bussonniermatthias@gmail.com>
5 years agobpo-42260: PyConfig_Read() only parses argv once (GH-23168)
Victor Stinner [Thu, 5 Nov 2020 17:58:07 +0000 (18:58 +0100)] 
bpo-42260: PyConfig_Read() only parses argv once (GH-23168)

The PyConfig_Read() function now only parses PyConfig.argv arguments
once: PyConfig.parse_argv is set to 2 after arguments are parsed.
Since Python arguments are strippped from PyConfig.argv, parsing
arguments twice would parse the application options as Python
options.

* Rework the PyConfig documentation.
* Fix _testinternalcapi.set_config() error handling.
* SetConfigTests no longer needs parse_argv=0 when restoring the old
  configuration.

5 years agobpo-42260: Add _PyConfig_FromDict() (GH-23167)
Victor Stinner [Thu, 5 Nov 2020 17:12:33 +0000 (18:12 +0100)] 
bpo-42260: Add _PyConfig_FromDict() (GH-23167)

* Rename config_as_dict() to _PyConfig_AsDict().
* Add 'module_search_paths_set' to _PyConfig_AsDict().
* Add _PyConfig_FromDict().
* Add get_config() and set_config() to _testinternalcapi.
* Add config_check_consistency().

5 years agobpo-41877 Check for asert, aseert, assrt in mocks (GH-23165)
vabr-g [Thu, 5 Nov 2020 17:04:38 +0000 (18:04 +0100)] 
bpo-41877 Check for asert, aseert, assrt in mocks (GH-23165)

Currently, a Mock object which is not unsafe will raise an
AttributeError if an attribute with the prefix assert or assret is
accessed on it. This protects against misspellings of real assert
method calls, which lead to tests passing silently even if the tested
code does not satisfy the intended assertion.

Recently a check was done in a large code base (Google) and three
more frequent ways of misspelling assert were found causing harm:
asert, aseert, assrt. These are now added to the existing check.

5 years ago[docs] fix wrongly named AsyncContextDecorator (GH-23164)
kj [Thu, 5 Nov 2020 16:16:27 +0000 (00:16 +0800)] 
[docs] fix wrongly named AsyncContextDecorator (GH-23164)

Also added versionchanged.

5 years agobpo-42262: Add Py_NewRef() and Py_XNewRef() (GH-23152)
Victor Stinner [Thu, 5 Nov 2020 14:02:12 +0000 (15:02 +0100)] 
bpo-42262: Add Py_NewRef() and Py_XNewRef() (GH-23152)

Added Py_NewRef() and Py_XNewRef() functions to increment the reference
count of an object and return the object.

5 years agobpo-42266: Handle monkey-patching descriptors in LOAD_ATTR cache (GH-23157)
Pablo Galindo [Thu, 5 Nov 2020 09:23:15 +0000 (09:23 +0000)] 
bpo-42266: Handle monkey-patching descriptors in LOAD_ATTR cache (GH-23157)

5 years agobpo-40816 Add AsyncContextDecorator class (GH-20516)
Kazantcev Andrey [Thu, 5 Nov 2020 08:52:24 +0000 (11:52 +0300)] 
bpo-40816 Add AsyncContextDecorator class (GH-20516)

Co-authored-by: Yury Selivanov <yury@edgedb.com>
5 years agobpo-42260: Add _PyInterpreterState_SetConfig() (GH-23158)
Victor Stinner [Wed, 4 Nov 2020 23:45:56 +0000 (00:45 +0100)] 
bpo-42260: Add _PyInterpreterState_SetConfig() (GH-23158)

* Inline _PyInterpreterState_SetConfig(): replace it with
  _PyConfig_Copy().
* Add _PyErr_SetFromPyStatus()
* Add _PyInterpreterState_GetConfigCopy()
* Add a new _PyInterpreterState_SetConfig() function.
* Add an unit which gets, modifies, and sets the config.

5 years agoDisable peg generator tests when building with PGO (GH-23141)
serge-sans-paille [Wed, 4 Nov 2020 23:01:08 +0000 (23:01 +0000)] 
Disable peg generator tests when building with PGO (GH-23141)

Otherwise, when running the testsuite, test_peg_generator tries to compile C
code using the optimized flags and fails because it cannot find the profile
data.

5 years agobpo-1635741: _sqlite3 uses PyModule_AddObjectRef() (GH-23148)
Erlend Egeberg Aasland [Wed, 4 Nov 2020 19:31:51 +0000 (20:31 +0100)] 
bpo-1635741: _sqlite3 uses PyModule_AddObjectRef() (GH-23148)

5 years agobpo-1635741: Fix PyInit_pyexpat() error handling (GH-22489)
Mohamed Koubaa [Wed, 4 Nov 2020 17:37:23 +0000 (11:37 -0600)] 
bpo-1635741: Fix PyInit_pyexpat() error handling (GH-22489)

Split PyInit_pyexpat() into sub-functions and fix reference leaks
on error paths.

5 years agobpo-42260: Main init modify sys.flags in-place (GH-23150)
Victor Stinner [Wed, 4 Nov 2020 16:34:34 +0000 (17:34 +0100)] 
bpo-42260: Main init modify sys.flags in-place (GH-23150)

When Py_Initialize() is called twice, the second call now updates
more sys attributes for the configuration, rather than only sys.argv.

* Rename _PySys_InitMain() to _PySys_UpdateConfig().
* _PySys_UpdateConfig() now modifies sys.flags in-place, instead of
  creating a new flags object.
* Remove old commented sys.flags flags (unbuffered and skip_first).
* Add private _PySys_GetObject() function.
* When Py_Initialize(), Py_InitializeFromConfig() and

5 years agobpo-1635741: Fix ref leak in _PyWarnings_Init() error path (GH-23151)
Victor Stinner [Wed, 4 Nov 2020 16:33:06 +0000 (17:33 +0100)] 
bpo-1635741: Fix ref leak in _PyWarnings_Init() error path (GH-23151)

Replace PyModule_AddObject() with PyModule_AddObjectRef() in the
_warnings module to fix a reference leak on error.

Use also PyModule_AddObjectRef() in importdl.c.

5 years agobpo-1635741: _ast uses PyModule_AddObjectRef() (GH-23146)
Victor Stinner [Wed, 4 Nov 2020 15:37:07 +0000 (16:37 +0100)] 
bpo-1635741: _ast uses PyModule_AddObjectRef() (GH-23146)

Replace PyModule_AddObject() with PyModule_AddObjectRef() in the _ast
module (Python-ast.c).

5 years agobpo-1635741: _contextvars uses PyModule_AddType() (GH-23147)
Victor Stinner [Wed, 4 Nov 2020 15:33:55 +0000 (16:33 +0100)] 
bpo-1635741: _contextvars uses PyModule_AddType() (GH-23147)

Replace PyModule_AddObject() with PyModule_AddType() in the
_contextvars module (Python-ast.c).

Add also the module name to _contextvars types name.

5 years agobpo-42260: Reorganize PyConfig (GH-23149)
Victor Stinner [Wed, 4 Nov 2020 15:15:54 +0000 (16:15 +0100)] 
bpo-42260: Reorganize PyConfig (GH-23149)

* Move orig_argv before argv
* Move program_name and platlibdir with other path configuration
  inputs

Give a name to the PyPreConfig and PyConfig structures and separate
the type definitions.

5 years agobpo-1635741: Add PyModule_AddObjectRef() function (GH-23122)
Victor Stinner [Wed, 4 Nov 2020 12:59:15 +0000 (13:59 +0100)] 
bpo-1635741: Add PyModule_AddObjectRef() function (GH-23122)

Added PyModule_AddObjectRef() function: similar to
PyModule_AddObjectRef() but don't steal a reference to the value on
success.

5 years agobpo-42236: os.device_encoding() respects UTF-8 Mode (GH-23119)
Victor Stinner [Wed, 4 Nov 2020 10:20:10 +0000 (11:20 +0100)] 
bpo-42236: os.device_encoding() respects UTF-8 Mode (GH-23119)

On Unix, the os.device_encoding() function now returns 'UTF-8' rather
than the device encoding if the Python UTF-8 Mode is enabled.

5 years agobpo-42251: Add gettrace and getprofile to threading (GH-23125)
Mario Corchero [Wed, 4 Nov 2020 09:27:43 +0000 (10:27 +0100)] 
bpo-42251: Add gettrace and getprofile to threading (GH-23125)

This allows to retrieve the functions that were set in these two, which might differ from sys.gettrace and sys.getprofile within a thread.

5 years agoEnable signing of nuget.org packages and update to supported timestamp server (GH...
Steve Dower [Tue, 3 Nov 2020 22:31:49 +0000 (22:31 +0000)] 
Enable signing of nuget.org packages and update to supported timestamp server (GH-23132)

5 years agoFix incorrect links in ast docs (GH-23017)
Matthew Suozzo [Tue, 3 Nov 2020 21:28:42 +0000 (16:28 -0500)] 
Fix incorrect links in ast docs (GH-23017)

5 years agoAdd _PyType_GetModuleByDef (GH-22835)
Petr Viktorin [Tue, 3 Nov 2020 21:27:12 +0000 (22:27 +0100)] 
Add _PyType_GetModuleByDef (GH-22835)

See https://mail.python.org/archives/list/capi-sig@python.org/thread/T3P2QNLNLBRFHWSKYSTPMVEIL2EEKFJU/ for discussion.

https://bugs.python.org/issue42100

5 years agoPost 3.10.0a2
Pablo Galindo [Tue, 3 Nov 2020 17:31:32 +0000 (17:31 +0000)] 
Post 3.10.0a2

5 years agoMerge tag 'v3.10.0a2' into master
Pablo Galindo [Tue, 3 Nov 2020 17:30:57 +0000 (17:30 +0000)] 
Merge tag 'v3.10.0a2' into master

Python 3.10.0a2

5 years agobpo-41796: Call _PyAST_Fini() earlier to fix a leak (GH-23131)
Victor Stinner [Tue, 3 Nov 2020 17:07:15 +0000 (18:07 +0100)] 
bpo-41796: Call _PyAST_Fini() earlier to fix a leak (GH-23131)

Call _PyAST_Fini() on all interpreters, not only on the main
interpreter. Also, call it ealier to fix a reference leak.

Python types contain a reference to themselves in in their
PyTypeObject.tp_mro member. _PyAST_Fini() must called before the last
GC collection to destroy AST types.

_PyInterpreterState_Clear() now calls _PyAST_Fini(). It now also
calls _PyWarnings_Fini() on subinterpeters, not only on the main
interpreter.

Add an assertion in AST init_types() to ensure that the _ast module
is no longer used after _PyAST_Fini() has been called.

5 years agobpo-42249: Fix writing binary Plist files larger than 4 GiB. (GH-23121)
Serhiy Storchaka [Tue, 3 Nov 2020 14:15:56 +0000 (16:15 +0200)] 
bpo-42249: Fix writing binary Plist files larger than 4 GiB. (GH-23121)

5 years agobpo-40077: Convert mmap.mmap static type to a heap type (GH-23108)
Erlend Egeberg Aasland [Tue, 3 Nov 2020 09:38:31 +0000 (10:38 +0100)] 
bpo-40077: Convert mmap.mmap static type to a heap type (GH-23108)

5 years agoPython 3.10.0a2 v3.10.0a2
Pablo Galindo [Tue, 3 Nov 2020 00:00:12 +0000 (00:00 +0000)] 
Python 3.10.0a2

5 years agobpo-35455: Fix thread_time for Solaris OS (GH-11118)
Jakub Kulík [Mon, 2 Nov 2020 23:10:01 +0000 (00:10 +0100)] 
bpo-35455: Fix thread_time for Solaris OS (GH-11118)

5 years agobpo-26789: Fix logging.FileHandler._open() at exit (GH-23053)
Victor Stinner [Mon, 2 Nov 2020 22:17:46 +0000 (23:17 +0100)] 
bpo-26789: Fix logging.FileHandler._open() at exit (GH-23053)

The logging.FileHandler class now keeps a reference to the builtin
open() function to be able to open or reopen the file during Python
finalization.

Fix errors like:

    Exception ignored in: (...)
    Traceback (most recent call last):
      (...)
      File ".../logging/__init__.py", line 1463, in error
      File ".../logging/__init__.py", line 1577, in _log
      File ".../logging/__init__.py", line 1587, in handle
      File ".../logging/__init__.py", line 1649, in callHandlers
      File ".../logging/__init__.py", line 948, in handle
      File ".../logging/__init__.py", line 1182, in emit
      File ".../logging/__init__.py", line 1171, in _open
    NameError: name 'open' is not defined

5 years agobpo-41796: Make _ast module state per interpreter (GH-23024)
Victor Stinner [Mon, 2 Nov 2020 21:03:28 +0000 (22:03 +0100)] 
bpo-41796: Make _ast module state per interpreter (GH-23024)

The ast module internal state is now per interpreter.

* Rename "astmodulestate" to "struct ast_state"
* Add pycore_ast.h internal header: the ast_state structure is now
  declared in pycore_ast.h.
* Add PyInterpreterState.ast (struct ast_state)
* Remove get_ast_state()
* Rename get_global_ast_state() to get_ast_state()
* PyAST_obj2mod() now handles get_ast_state() failures

5 years agobpo-42103: Improve validation of Plist files. (GH-22882)
Serhiy Storchaka [Mon, 2 Nov 2020 21:01:40 +0000 (23:01 +0200)] 
bpo-42103: Improve validation of Plist files. (GH-22882)

* Prevent some possible DoS attacks via providing invalid Plist files
  with extremely large number of objects or collection sizes.
* Raise InvalidFileException for too large bytes and string size instead of returning garbage.
* Raise InvalidFileException instead of ValueError for specific invalid datetime (NaN).
* Raise InvalidFileException instead of TypeError for non-hashable dict keys.
* Add more tests for invalid Plist files.

5 years agobpo-41943: Fix bug where assertLogs doesn't correctly filter messages… (GH-22565)
Irit Katriel [Mon, 2 Nov 2020 19:25:29 +0000 (19:25 +0000)] 
bpo-41943: Fix bug where assertLogs doesn't correctly filter messages… (GH-22565)

… by level

@vsajip , @pitrou

Automerge-Triggered-By: GH:vsajip
5 years agoRevert "bpo-37193: remove thread objects which finished process its request (GH-13893...
Jason R. Coombs [Mon, 2 Nov 2020 16:48:56 +0000 (11:48 -0500)] 
Revert "bpo-37193: remove thread objects which finished process its request (GH-13893)" (GH-23107)

This reverts commit c41559021213cfc9dc62a83fc63306b3bdc3e64b.

5 years agobpo-42236: Enhance init and encoding documentation (GH-23109)
Victor Stinner [Mon, 2 Nov 2020 15:49:54 +0000 (16:49 +0100)] 
bpo-42236: Enhance init and encoding documentation (GH-23109)

Enhance the documentation of the Python startup, filesystem encoding
and error handling, locale encoding. Add a new "Python UTF-8 Mode"
section.

* Add "locale encoding" and "filesystem encoding and error handler"
  to the glossary
* Remove documentation from Include/cpython/initconfig.h: move it to
  Doc/c-api/init_config.rst.
* Doc/c-api/init_config.rst:

  * Document command line options and environment variables
  * Document default values.

* Add a new "Python UTF-8 Mode" section in Doc/library/os.rst.
* Add warnings to Py_DecodeLocale() and Py_EncodeLocale() docs.
* Document how Python selects the filesystem encoding and error
  handler at a single place: PyConfig.filesystem_encoding and
  PyConfig.filesystem_errors.
* PyConfig: move orig_argv member at the right place.

5 years agobpo-42224: Fix test_format when locale does not expect number grouping (GH-23067)
Lysandros Nikolaou [Mon, 2 Nov 2020 15:27:30 +0000 (17:27 +0200)] 
bpo-42224: Fix test_format when locale does not expect number grouping (GH-23067)

5 years agobpo-41435: Add sys._current_exceptions() function (GH-21689)
Julien Danjou [Mon, 2 Nov 2020 14:16:25 +0000 (15:16 +0100)] 
bpo-41435: Add sys._current_exceptions() function (GH-21689)

This adds a new function named sys._current_exceptions() which is equivalent ot
sys._current_frames() except that it returns the exceptions currently handled
by other threads. It is equivalent to calling sys.exc_info() for each running
thread.

5 years agobpo-42230: Improve asyncio documentation regarding accepting sets vs iterables (GH...
Jakub Stasiak [Mon, 2 Nov 2020 10:56:35 +0000 (11:56 +0100)] 
bpo-42230: Improve asyncio documentation regarding accepting sets vs iterables (GH-23073)

People call wait() and as_completed() with various non-set iterables,
a list should be the most common but there are others as well[1].

Considering typeshed also documents wait()[2] and as_completed()[3]
as accepting arbitrary iterables I think it's a good idea to document
the status quo better.

[1] https://github.com/aio-libs/aiokafka/pull/672
[2] https://github.com/python/typeshed/blob/620989bac572f30349b95590ebe81a73ce0fe862/stdlib/3/asyncio/tasks.pyi#L161
[3] https://github.com/python/typeshed/blob/620989bac572f30349b95590ebe81a73ce0fe862/stdlib/3/asyncio/tasks.pyi#L40

5 years agobpo-41229: Update docs for explicit aclose()-required cases and add contextlib.aclosi...
Joongi Kim [Mon, 2 Nov 2020 08:02:48 +0000 (17:02 +0900)] 
bpo-41229: Update docs for explicit aclose()-required cases and add contextlib.aclosing() method (GH-21545)

This is a PR to:

 * Add `contextlib.aclosing` which ia analogous to `contextlib.closing` but for async-generators with an explicit test case for [bpo-41229]()
 * Update the docs to describe when we need explicit `aclose()` invocation.

which are motivated by the following issues, articles, and examples:

 * [bpo-41229]()
 * https://github.com/njsmith/async_generator
 * https://vorpus.org/blog/some-thoughts-on-asynchronous-api-design-in-a-post-asyncawait-world/#cleanup-in-generators-and-async-generators
 * https://www.python.org/dev/peps/pep-0533/
 * https://github.com/achimnol/aiotools/blob/ef7bf0cea7af/src/aiotools/context.py#L152

Particuarly regarding [PEP-533](https://www.python.org/dev/peps/pep-0533/), its acceptance (`__aiterclose__()`) would make this little addition of `contextlib.aclosing()` unnecessary for most use cases, but until then this could serve as a good counterpart and analogy to `contextlib.closing()`. The same applies for `contextlib.closing` with `__iterclose__()`.
Also, still there are other use cases, e.g., when working with non-generator objects with `aclose()` methods.

5 years agoMinor formatting edits to the descriptor howto guide (GH-23092)
Raymond Hettinger [Mon, 2 Nov 2020 04:15:50 +0000 (20:15 -0800)] 
Minor formatting edits to the descriptor howto guide (GH-23092)

5 years agobpo-40511: Stop unwanted flashing of IDLE calltips (GH-20910)
Tal Einat [Mon, 2 Nov 2020 03:59:52 +0000 (05:59 +0200)] 
bpo-40511: Stop unwanted flashing of IDLE calltips (GH-20910)

They were occurring with both repeated 'force-calltip' invocations and by typing parentheses
 in expressions, strings, and comments in the argument code.

Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
5 years agoAdd member objects to the descriptor howto guide (GH-23084)
Raymond Hettinger [Mon, 2 Nov 2020 02:02:37 +0000 (18:02 -0800)] 
Add member objects to the descriptor howto guide (GH-23084)

5 years agobpo-37193: remove thread objects which finished process its request (GH-13893)
MARUYAMA Norihiro [Sun, 1 Nov 2020 23:51:04 +0000 (08:51 +0900)] 
bpo-37193: remove thread objects which finished process its request (GH-13893)

* bpo-37193: remove the thread which finished process request from threads list

* rename variable t to thread.

* don't remove thread from list if it is daemon.

* use lock to protect self._threads.

* use finally block in case of exception from shutdown_request().

* check "not thread.daemon" before lock to avoid holding the lock if it's unnecessary.

* fix the place of _threads_lock.

* separate code to remove a current thread into a function.

* check ValueError when removing thread.

* fix wrong code which all instance shared same lock.

* Extract thread management into a _Threads class to encapsulate atomic operations and separate concerns.

* Replace multiple references of 'block_on_close' with one, avoiding the possibility that 'block_on_close' could change during the course of processing requests. Now, there's exactly one _threads object with behavior fixed for the duration.

* Add docstrings to private classes.

* Add test to ensure that a ThreadingTCPServer can be closed without serving any requests.

* Use _NoThreads as the default value. Fixes AttributeError when server is closed without serving any requests.

* Add blurb

* Add test capturing failure.

Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
5 years agobpo-42236: Use UTF-8 encoding if nl_langinfo(CODESET) fails (GH-23086)
Victor Stinner [Sun, 1 Nov 2020 22:07:23 +0000 (23:07 +0100)] 
bpo-42236: Use UTF-8 encoding if nl_langinfo(CODESET) fails (GH-23086)

If the nl_langinfo(CODESET) function returns an empty string, Python
now uses UTF-8 as the filesystem encoding.

In May 2010 (commit b744ba1d14c5487576c95d0311e357b707600b47), I
modified Python to log a warning and use UTF-8 as the filesystem
encoding (instead of None) if nl_langinfo(CODESET) returns an empty
string.

In August 2020 (commit 94908bbc1503df830d1d615e7b57744ae1b41079), I
modified Python startup to fail with a fatal error and a specific
error message if nl_langinfo(CODESET) returns an empty string. The
intent was to prevent guessing the encoding and also investigate user
configuration where this case happens.

In 10 years (2010 to 2020), I saw zero user report about the error
message related to nl_langinfo(CODESET) returning an empty string.

Today, UTF-8 became the defacto standard and it's safe to make the
assumption that the user expects UTF-8. For example,
nl_langinfo(CODESET) can return an empty string on macOS if the
LC_CTYPE locale is not supported, and UTF-8 is the default encoding
on macOS.

While this change is likely to not affect anyone in practice, it
should make UTF-8 lover happy ;-)

Rewrite also the documentation explaining how Python selects the
filesystem encoding and error handler.

5 years agobpo-42236: Enhance _locale._get_locale_encoding() (GH-23083)
Victor Stinner [Sun, 1 Nov 2020 19:59:35 +0000 (20:59 +0100)] 
bpo-42236: Enhance _locale._get_locale_encoding() (GH-23083)

* Rename _Py_GetLocaleEncoding() to _Py_GetLocaleEncodingObject()
* Add _Py_GetLocaleEncoding() which returns a wchar_t* string to
  share code between _Py_GetLocaleEncodingObject()
  and config_get_locale_encoding().
* _Py_GetLocaleEncodingObject() now decodes nl_langinfo(CODESET)
  from the current locale encoding with surrogateescape,
  rather than using UTF-8.

5 years agobpo-42233: Correctly repr GenericAlias when used with typing module (GH-23081)
kj [Sun, 1 Nov 2020 18:13:38 +0000 (02:13 +0800)] 
bpo-42233: Correctly repr GenericAlias when used with typing module (GH-23081)

Noticed by @serhiy-storchaka in the bpo.  `typing`'s types were not showing the parameterized generic.
Eg. previously:
```python
>>> typing.Union[dict[str, float], list[int]]
'typing.Union[dict, list]'
```
Now:
```python
>>> typing.Union[dict[str, float], list[int]]
'typing.Union[dict[str, float], list[int]]'
```

Automerge-Triggered-By: GH:gvanrossum
5 years agoExpand and clarify the "Invoking Descriptors" section of the Descriptor HowTo (GH...
Raymond Hettinger [Sun, 1 Nov 2020 17:10:06 +0000 (09:10 -0800)] 
Expand and clarify the "Invoking Descriptors" section of the Descriptor HowTo (GH-23078)

5 years agobpo-37483: Add PyObject_CallOneArg() in the What's New in Python 3.9 (GH-23062)
Dong-hee Na [Sun, 1 Nov 2020 13:04:35 +0000 (22:04 +0900)] 
bpo-37483: Add PyObject_CallOneArg() in the What's New in Python 3.9 (GH-23062)

5 years agotempfile: Use random.choises() instead of choise() (GH-23068)
Inada Naoki [Sun, 1 Nov 2020 11:02:03 +0000 (20:02 +0900)] 
tempfile: Use random.choises() instead of choise() (GH-23068)

5 years agobpo-29566: binhex.binhex now consitently writes MacOS 9 line endings. (GH-23059)
Ronald Oussoren [Sun, 1 Nov 2020 09:08:48 +0000 (10:08 +0100)] 
bpo-29566: binhex.binhex now consitently writes MacOS 9 line endings. (GH-23059)

[bpo-29566]() notes that binhex.binhex uses inconsistent line endings (both Unix and MacOS9 line endings are used). This PR changes this to use the MacOS9 line endings everywhere.

5 years agobpo-42146: Unify cleanup in subprocess_fork_exec() (GH-22970)
Alexey Izbyshev [Sun, 1 Nov 2020 05:33:08 +0000 (08:33 +0300)] 
bpo-42146: Unify cleanup in subprocess_fork_exec() (GH-22970)

* bpo-42146: Unify cleanup in subprocess_fork_exec()

Also ignore errors from _enable_gc():
* They are always suppressed by the current code due to a bug.
* _enable_gc() is only used if `preexec_fn != None`, which is unsafe.
* We don't have a good way to handle errors in case we successfully
  created a child process.

Co-authored-by: Gregory P. Smith <greg@krypto.org>
5 years agobpo-42198: New section in stdtypes for type annotation types (GH-23063)
kj [Sat, 31 Oct 2020 20:25:44 +0000 (04:25 +0800)] 
bpo-42198: New section in stdtypes for type annotation types (GH-23063)