Commit Graph

26811 Commits

Author SHA1 Message Date
Raymond Hettinger 7709037095
Small speed-up for the convolve() recipe. (GH-106371) 2023-07-03 15:38:38 -05:00
Mario Corchero d65b783b69
gh-61215: New mock to wait for multi-threaded events to happen (#16094)
mock: Add `ThreadingMock` class

Add a new class that allows to wait for a call to happen by using
`Event` objects. This mock class can be used to test and validate
expectations of multithreading code.

It uses two attributes for events to distinguish calls with any argument
and calls with specific arguments.

The calls with specific arguments need a lock to prevent two calls in
parallel from creating the same event twice.

The timeout is configured at class and constructor level to allow users
to set a timeout, we considered passing it as an argument to the
function but it could collide with a function parameter. Alternatively
we also considered passing it as positional only but from an API
caller perspective it was unclear what the first number meant on the
function call, think `mock.wait_until_called(1, "arg1", "arg2")`, where
1 is the timeout.

Lastly we also considered adding the new attributes to magic mock
directly rather than having a custom mock class for multi threading
scenarios, but we preferred to have specialised class that can be
composed if necessary. Additionally, having added it to `MagicMock`
directly would have resulted in `AsyncMock` having this logic, which
would not work as expected, since when if user "waits" on a
coroutine does not have the same meaning as waiting on a standard
call.

Co-authored-by: Karthikeyan Singaravelan <tir.karthi@gmail.com>
2023-07-03 07:56:54 +01:00
Ned Batchelder 987b712b4a
Replace the esoteric term 'datum' when describing dict comprehensions (#106119) 2023-07-02 20:22:40 -07:00
Inada Naoki 20b7c79b9d
gh-104922: Doc: add note about PY_SSIZE_T_CLEAN (#106314)
Add note about PY_SSIZE_T_CLEAN in extending and embedding document.
2023-07-03 00:54:35 +09:00
Victor Stinner 18b1fdebe0
gh-106320: Remove _PyInterpreterState_Get() alias (#106321)
Replace calls to the (removed) slow _PyInterpreterState_Get() with
fast inlined _PyInterpreterState_GET() function.
2023-07-01 23:44:07 +00:00
Victor Stinner 46d77610fc
gh-106316: Remove pytime.h header file (#106317)
Remove the "cpython/pytime.h" header file: it only contained private
functions. Move functions to the internal pycore_time.h header file.

Move tests from _testcapi to _testinternalcapi. Rename also test
methods to have the same name than tested C functions.

No longer export these functions:

* _PyTime_Add()
* _PyTime_As100Nanoseconds()
* _PyTime_FromMicrosecondsClamp()
* _PyTime_FromTimespec()
* _PyTime_FromTimeval()
* _PyTime_GetPerfCounterWithInfo()
* _PyTime_MulDiv()
2023-07-01 22:27:18 +00:00
Terry Jan Reedy 04dfc6fa90
gh-106232: Make timeit doc command lines compatible with Windows. (#106296)
Command Prompt (CMD Shell) and older versions of PowerShell
require double quotes and single quotes inside the string.
This form also works on linux and macOS.
2023-06-30 22:34:31 -04:00
F3eQnxN3RriK a8ae73965b
gh-101100: Docs: Fix references to several numeric dunders (#106278)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-06-30 15:27:09 +01:00
Victor Stinner 80b3d8f337
gh-106023: Remove _PyObject_FastCallTstate() function (#106273) 2023-06-30 12:28:59 +02:00
Victor Stinner f3cf2ddd8d
gh-77782: Deprecate Py_HasFileSystemDefaultEncoding (#106272)
Deprecate Py_HasFileSystemDefaultEncoding variable.
2023-06-30 11:57:06 +02:00
Victor Stinner 2efdd2a14e
gh-106023: Remove _PyObject_FastCall() function (#106265) 2023-06-30 11:46:43 +02:00
Brandt Bucher 7b2d94d875
GH-106008: Make implicit boolean conversions explicit (GH-106003) 2023-06-29 13:49:54 -07:00
hms 8bff940ad6
gh-105775: Convert LOAD_CLOSURE to a pseudo-op (#106059)
This enables super-instruction formation,
removal of checks for uninitialized variables,
and frees up an instruction.
2023-06-29 09:34:00 -07:00
F3eQnxN3RriK 18f51f91e2
gh-101100: Fix reference to `parse_args` in `optparse.rst` (#105265) 2023-06-28 15:30:26 +03:00
F3eQnxN3RriK bbf722dcd3
gh-101100: Fix reference to asynchronous methods (#106172) 2023-06-28 10:43:11 +00:00
Sam Bull 6b52a581c1
gh-105993: Add possible `None` return type to `asyncio.EventLoop.start_tls` docs (#105995) 2023-06-28 16:08:15 +05:30
lightdrk 541a10f9ed
Refer to `TimeoutError` instead of `asyncio.TimeoutError` in `asyncio-task.rst` (#106136)
Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
2023-06-27 23:21:38 -06:00
Victor Stinner 3f8483cad2
gh-106168: PyTuple_SET_ITEM() now checks the index (#106164)
PyTuple_SET_ITEM() and PyList_SET_ITEM() now check the index argument
with an assertion if Python is built in debug mode or is built with
assertions.

* list_extend() and _PyList_AppendTakeRef() now set the list size
  before calling PyList_SET_ITEM().
* PyStructSequence_GetItem() and PyStructSequence_SetItem() now check
  the index argument: must be lesser than REAL_SIZE(op).
* PyStructSequence_GET_ITEM() and PyStructSequence_SET_ITEM() are now
  aliases to PyStructSequence_GetItem() and
  PyStructSequence_SetItem().
2023-06-28 03:45:57 +02:00
Nikita Sobolev 33608fd67d
gh-92788: Add docs for `ast.Module`, `ast.Expression`, and others (#101055) 2023-06-27 06:43:49 -07:00
Raymond Hettinger a8210b6df1
GH-105774: Clarify operation of normalize() (GH-106093) 2023-06-26 23:12:22 -05:00
Łukasz Langa d3af83b934
Revert "GH-96145: Add AttrDict to JSON module for use with object_hook (#96146)" (#105948)
This reverts commit 1f0eafa844.
2023-06-26 20:35:53 +02:00
Roderich Schupp 512f299e55
gh-106107: document correct error that's raised when a mutable default value for a field is detected (gh-106109) 2023-06-26 14:00:21 -04:00
Barney Gale 219effa876
GH-105793: Add follow_symlinks argument to `pathlib.Path.is_dir()` and `is_file()` (GH-105794)
Brings `pathlib.Path.is_dir()` and `in line with `os.DirEntry.is_dir()`, which
will be important for implementing generic path walking and globbing.
Likewise `is_file()`.
2023-06-26 17:58:17 +01:00
Paul Moore 5d4dbf0e30
gh-106111: Remove zipapp documentation on creating a Windows executable (#106112)
Remove zipapp documentation on creating a Windows executable
2023-06-26 18:14:20 +02:00
Victor Stinner c075a1974b
gh-105927: Deprecate PyWeakref_GetObject() function (#106006)
Deprecate PyWeakref_GetObject() and PyWeakref_GET_OBJECT() functions.
2023-06-26 12:10:53 +02:00
Alex Waygood 3eeb8c8906
Improve typing docs on the type of class objects (#106081) 2023-06-26 00:13:48 -07:00
Victor Stinner 00e75a3372
gh-106084: Remove old PyObject call aliases (#106085)
Remove old aliases which were kept backwards compatibility with
Python 3.8:

* _PyObject_CallMethodNoArgs()
* _PyObject_CallMethodOneArg()
* _PyObject_CallOneArg()
* _PyObject_FastCallDict()
* _PyObject_Vectorcall()
* _PyObject_VectorcallMethod()
* _PyVectorcall_Function()

Update code which used these aliases to use new names.
2023-06-26 08:08:12 +02:00
Alex Waygood 93a970ffbc
gh-106046: Improve error message from `os.fspath` if `__fspath__` is set to `None` (#106082) 2023-06-26 00:06:12 +01:00
Erlend E. Aasland bef1c8761e
Docs: add links to 'callable' term in sqlite3 docs (#106072) 2023-06-25 02:02:59 +02:00
Gregory P. Smith 19d6511b0b
gh-106033: [docs] Improve C API GetItem & HasAttr notes. (#106047)
Use a note:: tag so that these dict and object API deficiencies show up clearly.

A caution:: tag was considered, but our current python docs rendering doesn't do much with that (no box or color change).  warning:: seemed too extreme.  note looks good.
2023-06-24 16:29:26 -07:00
Barney Gale 4a6c84fc1e
GH-104375: Use `versionchanged` to describe new arguments in pathlib docs (GH-104376) 2023-06-24 16:14:09 +01:00
Eamon Tracey 8ef0ee4ebc
Typing docs: fix typo in annotating tuples comment (#106048) 2023-06-23 21:34:05 +01:00
Irit Katriel d8ca5a11bc
gh-105730: support more callables in ExceptionGroup.split() and subgroup() (#106035) 2023-06-23 19:47:47 +01:00
Alex Waygood 968435ddb1
Typing docs: improve the guidance on annotating tuples (#106021) 2023-06-23 15:33:20 +01:00
Alex Waygood a72683ba8e
Docs: Avoid a DeprecationWarning in `pyspecific.py` when running with Sphinx >=6.1 (#105886)
Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
2023-06-23 08:58:45 +01:00
Barney Gale a8006706f7
GH-89812: Add `pathlib.UnsupportedOperation` (GH-105926)
This new exception type is raised instead of `NotImplementedError` when
a path operation is not supported. It can be raised from `Path.readlink()`,
`symlink_to()`, `hardlink_to()`, `owner()` and `group()`. In a future
version of pathlib, it will be raised by `AbstractPath` for these methods
and others, such as `AbstractPath.mkdir()` and `unlink()`.
2023-06-22 14:35:51 +01:00
Victor Stinner 18a7c86697
gh-104212: Explain how to port imp.load_source() (#105978)
Explain how to port removed imp.load_source() to importlib in What's
New in Python 3.12.
2023-06-22 00:18:31 +02:00
Irit Katriel a2392720d6
gh-84436: update docs on Py_None/Py_True/Py_False/Py_Ellipsis becoming immortal (#105195) 2023-06-21 21:13:25 +01:00
Mathieu Dupuy c5a722be5f
stdtypes.rst: remove a period (#105959) 2023-06-21 15:21:37 +01:00
Sviatoslav Sydorenko eaa6702280
Use CSV-separated outputs @ get-changed-files @ CI (#105151)
Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
2023-06-21 13:42:59 +03:00
Victor Stinner 9c44656feb
gh-105927: Add PyWeakref_GetRef() function (#105932)
Add tests on PyWeakref_NewRef(), PyWeakref_GetObject(),
PyWeakref_GET_OBJECT() and PyWeakref_GetRef().
2023-06-21 11:40:09 +02:00
Victor Stinner 4d140e5e06
Add Py_TYPE() to Doc/data/refcounts.dat (#105949) 2023-06-20 23:57:54 +02:00
Victor Stinner 03f1a132ee
gh-105922: Add PyImport_AddModuleRef() function (#105923)
* Add tests on PyImport_AddModuleRef(), PyImport_AddModule() and
  PyImport_AddModuleObject().
* pythonrun.c: Replace Py_XNewRef(PyImport_AddModule(name)) with
  PyImport_AddModuleRef(name).
2023-06-20 08:48:14 +02:00
Victor Stinner 7a56a4148c
gh-104212: Explain how to port imp code to importlib (#105905) 2023-06-19 16:13:11 +02:00
Alex Waygood 4426279a43
typing docs: Improve the intro to each section (#105901) 2023-06-19 00:54:29 +01:00
Erlend E. Aasland 6849acb3fe
gh-105875: Require SQLite 3.15.2 or newer (#105876)
SQLite 3.15.2 was released 2016-11-28.
2023-06-19 00:29:08 +02:00
Hugo van Kemenade bc07c8f096
Docs: move sphinx-lint to pre-commit (#105750) 2023-06-18 11:52:05 +00:00
Erlend E. Aasland dba7217511
gh-105844: Use devguide terminology to denote versions (#105882) 2023-06-18 12:25:23 +02:00
Irit Katriel 14d01262da
gh-105481: remove HAS_ARG, HAS_CONST, IS_JUMP_OPCODE, IS_PSEUDO_OPCODE and replace by their new versions (#105865) 2023-06-17 17:00:16 +01:00
Carl Meyer b356a4749a
gh-105678: document SET_FUNCTION_ATTRIBUTE (#105843) 2023-06-16 12:36:59 -05:00