Skip to content

Commit 291ed52

Browse files
authored
Merge branch 'main' into remove_classmethod_descriptor_chaining
2 parents a7b0830 + 21f068d commit 291ed52

File tree

1,349 files changed

+33187
-19209
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,349 files changed

+33187
-19209
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,8 @@ indent_style = space
88
[*.{py,c,cpp,h}]
99
indent_size = 4
1010

11+
[*.rst]
12+
indent_size = 3
13+
1114
[*.yml]
1215
indent_size = 2

.github/ISSUE_TEMPLATE/bug.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ body:
3939
- "3.10"
4040
- "3.11"
4141
- "3.12"
42+
- "3.13"
4243
- "CPython main branch"
4344
validations:
4445
required: true

.github/workflows/build.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ jobs:
4040
run-docs: ${{ steps.docs-changes.outputs.run-docs || false }}
4141
run_tests: ${{ steps.check.outputs.run_tests }}
4242
run_hypothesis: ${{ steps.check.outputs.run_hypothesis }}
43+
run_cifuzz: ${{ steps.check.outputs.run_cifuzz }}
4344
config_hash: ${{ steps.config_hash.outputs.hash }}
4445
steps:
4546
- uses: actions/checkout@v4
@@ -76,6 +77,21 @@ jobs:
7677
echo "Run hypothesis tests"
7778
echo "run_hypothesis=true" >> $GITHUB_OUTPUT
7879
fi
80+
81+
# oss-fuzz maintains a configuration for fuzzing the main branch of
82+
# CPython, so CIFuzz should be run only for code that is likely to be
83+
# merged into the main branch; compatibility with older branches may
84+
# be broken.
85+
FUZZ_RELEVANT_FILES='(\.c$|\.h$|\.cpp$|^configure$|^\.github/workflows/build\.yml$|^Modules/_xxtestfuzz)'
86+
if [ "$GITHUB_BASE_REF" = "main" ] && [ "$(git diff --name-only origin/$GITHUB_BASE_REF.. | grep -qE $FUZZ_RELEVANT_FILES; echo $?)" -eq 0 ]; then
87+
# The tests are pretty slow so they are executed only for PRs
88+
# changing relevant files.
89+
echo "Run CIFuzz tests"
90+
echo "run_cifuzz=true" >> $GITHUB_OUTPUT
91+
else
92+
echo "Branch too old for CIFuzz tests; or no C files were changed"
93+
echo "run_cifuzz=false" >> $GITHUB_OUTPUT
94+
fi
7995
- name: Compute hash for config cache key
8096
id: config_hash
8197
run: |
@@ -534,6 +550,46 @@ jobs:
534550
- name: Tests
535551
run: xvfb-run make test
536552

553+
# CIFuzz job based on https://google.github.io/oss-fuzz/getting-started/continuous-integration/
554+
cifuzz:
555+
name: CIFuzz
556+
runs-on: ubuntu-latest
557+
timeout-minutes: 60
558+
needs: check_source
559+
if: needs.check_source.outputs.run_cifuzz == 'true'
560+
permissions:
561+
security-events: write
562+
strategy:
563+
fail-fast: false
564+
matrix:
565+
sanitizer: [address, undefined, memory]
566+
steps:
567+
- name: Build fuzzers (${{ matrix.sanitizer }})
568+
id: build
569+
uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master
570+
with:
571+
oss-fuzz-project-name: cpython3
572+
sanitizer: ${{ matrix.sanitizer }}
573+
- name: Run fuzzers (${{ matrix.sanitizer }})
574+
uses: google/oss-fuzz/infra/cifuzz/actions/run_fuzzers@master
575+
with:
576+
fuzz-seconds: 600
577+
oss-fuzz-project-name: cpython3
578+
output-sarif: true
579+
sanitizer: ${{ matrix.sanitizer }}
580+
- name: Upload crash
581+
uses: actions/upload-artifact@v3
582+
if: failure() && steps.build.outcome == 'success'
583+
with:
584+
name: ${{ matrix.sanitizer }}-artifacts
585+
path: ./out/artifacts
586+
- name: Upload SARIF
587+
if: always() && steps.build.outcome == 'success'
588+
uses: github/codeql-action/upload-sarif@v2
589+
with:
590+
sarif_file: cifuzz-sarif/results.sarif
591+
checkout_path: cifuzz-sarif
592+
537593
all-required-green: # This job does nothing and is only used for the branch protection
538594
name: All required checks pass
539595
if: always()
@@ -550,6 +606,7 @@ jobs:
550606
- build_ubuntu_ssltests
551607
- test_hypothesis
552608
- build_asan
609+
- cifuzz
553610

554611
runs-on: ubuntu-latest
555612

@@ -562,6 +619,7 @@ jobs:
562619
build_ubuntu_ssltests,
563620
build_win32,
564621
build_win_arm64,
622+
cifuzz,
565623
test_hypothesis,
566624
allowed-skips: >-
567625
${{
@@ -585,6 +643,13 @@ jobs:
585643
'
586644
|| ''
587645
}}
646+
${{
647+
!fromJSON(needs.check_source.outputs.run_cifuzz)
648+
&& '
649+
cifuzz,
650+
'
651+
|| ''
652+
}}
588653
${{
589654
!fromJSON(needs.check_source.outputs.run_hypothesis)
590655
&& '

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ permissions:
77

88
env:
99
FORCE_COLOR: 1
10-
RUFF_FORMAT: github
10+
RUFF_OUTPUT_FORMAT: github
1111

1212
concurrency:
1313
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ gmon.out
4242
.coverage
4343
.mypy_cache/
4444
.pytest_cache/
45+
.ruff_cache/
4546
.DS_Store
4647

4748
*.exe

.pre-commit-config.yaml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
repos:
22
- repo: https://github.com/astral-sh/ruff-pre-commit
3-
rev: v0.0.292
3+
rev: v0.1.2
44
hooks:
55
- id: ruff
66
name: Run Ruff on Lib/test/
77
args: [--exit-non-zero-on-fix]
88
files: ^Lib/test/
9+
- id: ruff
10+
name: Run Ruff on Argument Clinic
11+
args: [--exit-non-zero-on-fix, --config=Tools/clinic/.ruff.toml]
12+
files: ^Tools/clinic/|Lib/test/test_clinic.py
913

1014
- repo: https://github.com/pre-commit/pre-commit-hooks
11-
rev: v4.4.0
15+
rev: v4.5.0
1216
hooks:
1317
- id: check-toml
1418
exclude: ^Lib/test/test_tomllib/
@@ -17,12 +21,16 @@ repos:
1721
types: [python]
1822
exclude: Lib/test/tokenizedata/coding20731.py
1923
- id: trailing-whitespace
20-
types_or: [c, python, rst]
24+
types_or: [c, inc, python, rst]
2125

2226
- repo: https://github.com/sphinx-contrib/sphinx-lint
23-
rev: v0.6.8
27+
rev: v0.8.1
2428
hooks:
2529
- id: sphinx-lint
2630
args: [--enable=default-role]
2731
files: ^Doc/|^Misc/NEWS.d/next/
28-
types: [rst]
32+
33+
- repo: meta
34+
hooks:
35+
- id: check-hooks-apply
36+
- id: check-useless-excludes

Doc/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
PYTHON = python3
88
VENVDIR = ./venv
99
SPHINXBUILD = PATH=$(VENVDIR)/bin:$$PATH sphinx-build
10-
SPHINXLINT = PATH=$(VENVDIR)/bin:$$PATH sphinx-lint
1110
BLURB = PATH=$(VENVDIR)/bin:$$PATH blurb
1211
JOBS = auto
1312
PAPER =

Doc/c-api/arg.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,10 @@ API Functions
416416
.. c:function:: int PyArg_ParseTupleAndKeywords(PyObject *args, PyObject *kw, const char *format, char *keywords[], ...)
417417
418418
Parse the parameters of a function that takes both positional and keyword
419-
parameters into local variables. The *keywords* argument is a
420-
``NULL``-terminated array of keyword parameter names. Empty names denote
419+
parameters into local variables.
420+
The *keywords* argument is a ``NULL``-terminated array of keyword parameter
421+
names specified as null-terminated ASCII or UTF-8 encoded C strings.
422+
Empty names denote
421423
:ref:`positional-only parameters <positional-only_parameter>`.
422424
Returns true on success; on failure, it returns false and raises the
423425
appropriate exception.
@@ -426,6 +428,9 @@ API Functions
426428
Added support for :ref:`positional-only parameters
427429
<positional-only_parameter>`.
428430
431+
.. versionchanged:: 3.13
432+
Added support for non-ASCII keyword parameter names.
433+
429434
430435
.. c:function:: int PyArg_VaParseTupleAndKeywords(PyObject *args, PyObject *kw, const char *format, char *keywords[], va_list vargs)
431436

Doc/c-api/call.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ This is a pointer to a function with the following signature:
108108
Doing so will allow callables such as bound methods to make their onward
109109
calls (which include a prepended *self* argument) very efficiently.
110110

111+
.. versionadded:: 3.8
112+
111113
To call an object that implements vectorcall, use a :ref:`call API <capi-call>`
112114
function as with any other callable.
113115
:c:func:`PyObject_Vectorcall` will usually be most efficient.

Doc/c-api/init.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,19 @@ code, or when embedding the Python interpreter:
870870
When the current thread state is ``NULL``, this issues a fatal error (so that
871871
the caller needn't check for ``NULL``).
872872
873+
See also :c:func:`PyThreadState_GetUnchecked`.
874+
875+
876+
.. c:function:: PyThreadState* PyThreadState_GetUnchecked()
877+
878+
Similar to :c:func:`PyThreadState_Get`, but don't kill the process with a
879+
fatal error if it is NULL. The caller is responsible to check if the result
880+
is NULL.
881+
882+
.. versionadded:: 3.13
883+
In Python 3.5 to 3.12, the function was private and known as
884+
``_PyThreadState_UncheckedGet()``.
885+
873886
874887
.. c:function:: PyThreadState* PyThreadState_Swap(PyThreadState *tstate)
875888

Doc/c-api/init_config.rst

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ PyConfig
716716
717717
Set to ``1`` by the :envvar:`PYTHONDUMPREFS` environment variable.
718718
719-
Need a special build of Python with the ``Py_TRACE_REFS`` macro defined:
719+
Needs a special build of Python with the ``Py_TRACE_REFS`` macro defined:
720720
see the :option:`configure --with-trace-refs option <--with-trace-refs>`.
721721
722722
Default: ``0``.
@@ -878,6 +878,19 @@ PyConfig
878878
879879
.. versionadded:: 3.12
880880
881+
.. c:member:: int cpu_count
882+
883+
If the value of :c:member:`~PyConfig.cpu_count` is not ``-1`` then it will
884+
override the return values of :func:`os.cpu_count`,
885+
:func:`os.process_cpu_count`, and :func:`multiprocessing.cpu_count`.
886+
887+
Configured by the :samp:`-X cpu_count={n|default}` command line
888+
flag or the :envvar:`PYTHON_CPU_COUNT` environment variable.
889+
890+
Default: ``-1``.
891+
892+
.. versionadded:: 3.13
893+
881894
.. c:member:: int isolated
882895
883896
If greater than ``0``, enable isolated mode:
@@ -1035,7 +1048,7 @@ PyConfig
10351048
Incremented by the :option:`-d` command line option. Set to the
10361049
:envvar:`PYTHONDEBUG` environment variable value.
10371050
1038-
Need a :ref:`debug build of Python <debug-build>` (the ``Py_DEBUG`` macro
1051+
Needs a :ref:`debug build of Python <debug-build>` (the ``Py_DEBUG`` macro
10391052
must be defined).
10401053
10411054
Default: ``0``.
@@ -1087,6 +1100,7 @@ PyConfig
10871100
10881101
Set by the :option:`-X pycache_prefix=PATH <-X>` command line option and
10891102
the :envvar:`PYTHONPYCACHEPREFIX` environment variable.
1103+
The command-line option takes precedence.
10901104
10911105
If ``NULL``, :data:`sys.pycache_prefix` is set to ``None``.
10921106
@@ -1130,13 +1144,27 @@ PyConfig
11301144
11311145
Default: ``NULL``.
11321146
1147+
.. c:member:: wchar_t* run_presite
1148+
1149+
``package.module`` path to module that should be imported before
1150+
``site.py`` is run.
1151+
1152+
Set by the :option:`-X presite=package.module <-X>` command-line
1153+
option and the :envvar:`PYTHON_PRESITE` environment variable.
1154+
The command-line option takes precedence.
1155+
1156+
Needs a :ref:`debug build of Python <debug-build>` (the ``Py_DEBUG`` macro
1157+
must be defined).
1158+
1159+
Default: ``NULL``.
1160+
11331161
.. c:member:: int show_ref_count
11341162
11351163
Show total reference count at exit (excluding immortal objects)?
11361164
11371165
Set to ``1`` by :option:`-X showrefcount <-X>` command line option.
11381166
1139-
Need a :ref:`debug build of Python <debug-build>` (the ``Py_REF_DEBUG``
1167+
Needs a :ref:`debug build of Python <debug-build>` (the ``Py_REF_DEBUG``
11401168
macro must be defined).
11411169
11421170
Default: ``0``.

Doc/c-api/memory.rst

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -491,18 +491,18 @@ Customize Memory Allocators
491491
492492
:c:func:`PyMem_SetAllocator` does have the following contract:
493493
494-
* It can be called after :c:func:`Py_PreInitialize` and before
495-
:c:func:`Py_InitializeFromConfig` to install a custom memory
496-
allocator. There are no restrictions over the installed allocator
497-
other than the ones imposed by the domain (for instance, the Raw
498-
Domain allows the allocator to be called without the GIL held). See
499-
:ref:`the section on allocator domains <allocator-domains>` for more
500-
information.
501-
502-
* If called after Python has finish initializing (after
503-
:c:func:`Py_InitializeFromConfig` has been called) the allocator
504-
**must** wrap the existing allocator. Substituting the current
505-
allocator for some other arbitrary one is **not supported**.
494+
* It can be called after :c:func:`Py_PreInitialize` and before
495+
:c:func:`Py_InitializeFromConfig` to install a custom memory
496+
allocator. There are no restrictions over the installed allocator
497+
other than the ones imposed by the domain (for instance, the Raw
498+
Domain allows the allocator to be called without the GIL held). See
499+
:ref:`the section on allocator domains <allocator-domains>` for more
500+
information.
501+
502+
* If called after Python has finish initializing (after
503+
:c:func:`Py_InitializeFromConfig` has been called) the allocator
504+
**must** wrap the existing allocator. Substituting the current
505+
allocator for some other arbitrary one is **not supported**.
506506
507507
.. versionchanged:: 3.12
508508
All allocators must be thread-safe.
@@ -626,7 +626,8 @@ The pymalloc allocator
626626
627627
Python has a *pymalloc* allocator optimized for small objects (smaller or equal
628628
to 512 bytes) with a short lifetime. It uses memory mappings called "arenas"
629-
with a fixed size of 256 KiB. It falls back to :c:func:`PyMem_RawMalloc` and
629+
with a fixed size of either 256 KiB on 32-bit platforms or 1 MiB on 64-bit
630+
platforms. It falls back to :c:func:`PyMem_RawMalloc` and
630631
:c:func:`PyMem_RawRealloc` for allocations larger than 512 bytes.
631632
632633
*pymalloc* is the :ref:`default allocator <default-memory-allocators>` of the

Doc/c-api/set.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,6 @@ subtypes but not for instances of :class:`frozenset` or its subtypes.
163163
164164
.. c:function:: int PySet_Clear(PyObject *set)
165165
166-
Empty an existing set of all elements.
166+
Empty an existing set of all elements. Return ``0`` on
167+
success. Return ``-1`` and raise :exc:`SystemError` if *set* is not an instance of
168+
:class:`set` or its subtype.

Doc/c-api/structures.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,11 @@ Accessing attributes of extension types
406406
.. c:type:: PyMemberDef
407407
408408
Structure which describes an attribute of a type which corresponds to a C
409-
struct member. Its fields are, in order:
409+
struct member.
410+
When defining a class, put a NULL-terminated array of these
411+
structures in the :c:member:`~PyTypeObject.tp_members` slot.
412+
413+
Its fields are, in order:
410414
411415
.. c:member:: const char* name
412416

0 commit comments

Comments
 (0)