Skip to content

Commit 98e5920

Browse files
committed
Merge branch 'main' into pythongh-127794
2 parents f2bbb92 + 474e419 commit 98e5920

File tree

177 files changed

+9195
-5008
lines changed

Some content is hidden

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

177 files changed

+9195
-5008
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
# reproducible: to get the same tools versions (autoconf, aclocal, ...)
4747
runs-on: ubuntu-24.04
4848
container:
49-
image: ghcr.io/python/autoconf:2024.11.11.11786316759
49+
image: ghcr.io/python/autoconf:2025.01.02.12581854023
5050
timeout-minutes: 60
5151
needs: check_source
5252
if: needs.check_source.outputs.run_tests == 'true'
@@ -63,7 +63,7 @@ jobs:
6363
run: echo "IMAGE_VERSION=${ImageVersion}" >> "$GITHUB_ENV"
6464
- name: Check Autoconf and aclocal versions
6565
run: |
66-
grep "Generated by GNU Autoconf 2.71" configure
66+
grep "Generated by GNU Autoconf 2.72" configure
6767
grep "aclocal 1.16.5" aclocal.m4
6868
grep -q "runstatedir" configure
6969
grep -q "PKG_PROG_PKG_CONFIG" aclocal.m4

.github/workflows/reusable-docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ jobs:
9999
# Run "doctest" on HEAD as new syntax doesn't exist in the latest stable release
100100
doctest:
101101
name: 'Doctest'
102-
runs-on: ubuntu-22.04
102+
runs-on: ubuntu-24.04
103103
timeout-minutes: 60
104104
steps:
105105
- uses: actions/checkout@v4

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ repos:
5555
hooks:
5656
- id: check-dependabot
5757
- id: check-github-workflows
58+
- id: check-readthedocs
5859

5960
- repo: https://github.com/rhysd/actionlint
6061
rev: v1.7.4

Doc/c-api/arg.rst

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,24 @@ There are three ways strings and buffers can be converted to C:
229229
Numbers
230230
-------
231231

232+
These formats allow representing Python numbers or single characters as C numbers.
233+
Formats that require :class:`int`, :class:`float` or :class:`complex` can
234+
also use the corresponding special methods :meth:`~object.__index__`,
235+
:meth:`~object.__float__` or :meth:`~object.__complex__` to convert
236+
the Python object to the required type.
237+
238+
For signed integer formats, :exc:`OverflowError` is raised if the value
239+
is out of range for the C type.
240+
For unsigned integer formats, no range checking is done --- the
241+
most significant bits are silently truncated when the receiving field is too
242+
small to receive the value.
243+
232244
``b`` (:class:`int`) [unsigned char]
233-
Convert a nonnegative Python integer to an unsigned tiny int, stored in a C
245+
Convert a nonnegative Python integer to an unsigned tiny integer, stored in a C
234246
:c:expr:`unsigned char`.
235247

236248
``B`` (:class:`int`) [unsigned char]
237-
Convert a Python integer to a tiny int without overflow checking, stored in a C
249+
Convert a Python integer to a tiny integer without overflow checking, stored in a C
238250
:c:expr:`unsigned char`.
239251

240252
``h`` (:class:`int`) [short int]
@@ -307,7 +319,7 @@ Other objects
307319

308320
.. _o_ampersand:
309321

310-
``O&`` (object) [*converter*, *anything*]
322+
``O&`` (object) [*converter*, *address*]
311323
Convert a Python object to a C variable through a *converter* function. This
312324
takes two arguments: the first is a function, the second is the address of a C
313325
variable (of arbitrary type), converted to :c:expr:`void *`. The *converter*
@@ -321,14 +333,20 @@ Other objects
321333
the conversion has failed. When the conversion fails, the *converter* function
322334
should raise an exception and leave the content of *address* unmodified.
323335

324-
If the *converter* returns ``Py_CLEANUP_SUPPORTED``, it may get called a
336+
.. c:macro:: Py_CLEANUP_SUPPORTED
337+
:no-typesetting:
338+
339+
If the *converter* returns :c:macro:`!Py_CLEANUP_SUPPORTED`, it may get called a
325340
second time if the argument parsing eventually fails, giving the converter a
326341
chance to release any memory that it had already allocated. In this second
327342
call, the *object* parameter will be ``NULL``; *address* will have the same value
328343
as in the original call.
329344

345+
Examples of converters: :c:func:`PyUnicode_FSConverter` and
346+
:c:func:`PyUnicode_FSDecoder`.
347+
330348
.. versionchanged:: 3.1
331-
``Py_CLEANUP_SUPPORTED`` was added.
349+
:c:macro:`!Py_CLEANUP_SUPPORTED` was added.
332350

333351
``p`` (:class:`bool`) [int]
334352
Tests the value passed in for truth (a boolean **p**\ redicate) and converts
@@ -344,12 +362,6 @@ Other objects
344362
in *items*. The C arguments must correspond to the individual format units in
345363
*items*. Format units for sequences may be nested.
346364

347-
It is possible to pass "long" integers (integers whose value exceeds the
348-
platform's :c:macro:`LONG_MAX`) however no proper range checking is done --- the
349-
most significant bits are silently truncated when the receiving field is too
350-
small to receive the value (actually, the semantics are inherited from downcasts
351-
in C --- your mileage may vary).
352-
353365
A few other characters have a meaning in a format string. These may not occur
354366
inside nested parentheses. They are:
355367

Doc/c-api/object.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,13 @@ Object Protocol
493493
on failure. This is equivalent to the Python statement ``del o[key]``.
494494
495495
496+
.. c:function:: int PyObject_DelItemString(PyObject *o, const char *key)
497+
498+
This is the same as :c:func:`PyObject_DelItem`, but *key* is
499+
specified as a :c:expr:`const char*` UTF-8 encoded bytes string,
500+
rather than a :c:expr:`PyObject*`.
501+
502+
496503
.. c:function:: PyObject* PyObject_Dir(PyObject *o)
497504
498505
This is equivalent to the Python expression ``dir(o)``, returning a (possibly

Doc/c-api/sys.rst

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,38 @@ Operating System Utilities
216216
The function now uses the UTF-8 encoding on Windows if
217217
:c:member:`PyPreConfig.legacy_windows_fs_encoding` is zero.
218218
219+
.. c:function:: FILE* Py_fopen(PyObject *path, const char *mode)
220+
221+
Similar to :c:func:`!fopen`, but *path* is a Python object and
222+
an exception is set on error.
223+
224+
*path* must be a :class:`str` object, a :class:`bytes` object,
225+
or a :term:`path-like object`.
226+
227+
On success, return the new file pointer.
228+
On error, set an exception and return ``NULL``.
229+
230+
The file must be closed by :c:func:`Py_fclose` rather than calling directly
231+
:c:func:`!fclose`.
232+
233+
The file descriptor is created non-inheritable (:pep:`446`).
234+
235+
The caller must hold the GIL.
236+
237+
.. versionadded:: next
238+
239+
240+
.. c:function:: int Py_fclose(FILE *file)
241+
242+
Close a file that was opened by :c:func:`Py_fopen`.
243+
244+
On success, return ``0``.
245+
On error, return ``EOF`` and ``errno`` is set to indicate the error.
246+
In either case, any further access (including another call to
247+
:c:func:`Py_fclose`) to the stream results in undefined behavior.
248+
249+
.. versionadded:: next
250+
219251
220252
.. _systemfunctions:
221253

Doc/c-api/unicode.rst

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -786,33 +786,52 @@ Functions encoding to and decoding from the :term:`filesystem encoding and
786786
error handler` (:pep:`383` and :pep:`529`).
787787
788788
To encode file names to :class:`bytes` during argument parsing, the ``"O&"``
789-
converter should be used, passing :c:func:`PyUnicode_FSConverter` as the
789+
converter should be used, passing :c:func:`!PyUnicode_FSConverter` as the
790790
conversion function:
791791
792792
.. c:function:: int PyUnicode_FSConverter(PyObject* obj, void* result)
793793
794-
ParseTuple converter: encode :class:`str` objects -- obtained directly or
794+
:ref:`PyArg_Parse\* converter <arg-parsing>`: encode :class:`str` objects -- obtained directly or
795795
through the :class:`os.PathLike` interface -- to :class:`bytes` using
796796
:c:func:`PyUnicode_EncodeFSDefault`; :class:`bytes` objects are output as-is.
797-
*result* must be a :c:expr:`PyBytesObject*` which must be released when it is
798-
no longer used.
797+
*result* must be an address of a C variable of type :c:expr:`PyObject*`
798+
(or :c:expr:`PyBytesObject*`).
799+
On success, set the variable to a new :term:`strong reference` to
800+
a :ref:`bytes object <bytesobjects>` which must be released
801+
when it is no longer used and return a non-zero value
802+
(:c:macro:`Py_CLEANUP_SUPPORTED`).
803+
Embedded null bytes are not allowed in the result.
804+
On failure, return ``0`` with an exception set.
805+
806+
If *obj* is ``NULL``, the function releases a strong reference
807+
stored in the variable referred by *result* and returns ``1``.
799808
800809
.. versionadded:: 3.1
801810
802811
.. versionchanged:: 3.6
803812
Accepts a :term:`path-like object`.
804813
805814
To decode file names to :class:`str` during argument parsing, the ``"O&"``
806-
converter should be used, passing :c:func:`PyUnicode_FSDecoder` as the
815+
converter should be used, passing :c:func:`!PyUnicode_FSDecoder` as the
807816
conversion function:
808817
809818
.. c:function:: int PyUnicode_FSDecoder(PyObject* obj, void* result)
810819
811-
ParseTuple converter: decode :class:`bytes` objects -- obtained either
820+
:ref:`PyArg_Parse\* converter <arg-parsing>`: decode :class:`bytes` objects -- obtained either
812821
directly or indirectly through the :class:`os.PathLike` interface -- to
813822
:class:`str` using :c:func:`PyUnicode_DecodeFSDefaultAndSize`; :class:`str`
814-
objects are output as-is. *result* must be a :c:expr:`PyUnicodeObject*` which
815-
must be released when it is no longer used.
823+
objects are output as-is.
824+
*result* must be an address of a C variable of type :c:expr:`PyObject*`
825+
(or :c:expr:`PyUnicodeObject*`).
826+
On success, set the variable to a new :term:`strong reference` to
827+
a :ref:`Unicode object <unicodeobjects>` which must be released
828+
when it is no longer used and return a non-zero value
829+
(:c:macro:`Py_CLEANUP_SUPPORTED`).
830+
Embedded null characters are not allowed in the result.
831+
On failure, return ``0`` with an exception set.
832+
833+
If *obj* is ``NULL``, release the strong reference
834+
to the object referred to by *result* and return ``1``.
816835
817836
.. versionadded:: 3.2
818837

Doc/conf.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,7 @@
101101

102102
# Create table of contents entries for domain objects (e.g. functions, classes,
103103
# attributes, etc.). Default is True.
104-
toc_object_entries = True
105-
# Hide parents to tidy up long entries in sidebar
106-
toc_object_entries_show_parents = 'hide'
104+
toc_object_entries = False
107105

108106
# Ignore any .rst files in the includes/ directory;
109107
# they're embedded in pages but not rendered as individual pages.

Doc/howto/free-threading-extensions.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,10 @@ Most of the C API is thread-safe, but there are some exceptions.
9696

9797
* **Struct Fields**: Accessing fields in Python C API objects or structs
9898
directly is not thread-safe if the field may be concurrently modified.
99-
* **Macros**: Accessor macros like :c:macro:`PyList_GET_ITEM` and
100-
:c:macro:`PyList_SET_ITEM` do not perform any error checking or locking.
99+
* **Macros**: Accessor macros like :c:macro:`PyList_GET_ITEM`,
100+
:c:macro:`PyList_SET_ITEM`, and macros like
101+
:c:macro:`PySequence_Fast_GET_SIZE` that use the object returned by
102+
:c:func:`PySequence_Fast` do not perform any error checking or locking.
101103
These macros are not thread-safe if the container object may be modified
102104
concurrently.
103105
* **Borrowed References**: C API functions that return

Doc/library/calendar.rst

Lines changed: 75 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,33 @@ interpreted as prescribed by the ISO 8601 standard. Year 0 is 1 BC, year -1 is
3838
itself. This is the job of subclasses.
3939

4040

41-
:class:`Calendar` instances have the following methods:
41+
:class:`Calendar` instances have the following methods and attributes:
42+
43+
.. attribute:: firstweekday
44+
45+
The first weekday as an integer (0--6).
46+
47+
This property can also be set and read using
48+
:meth:`~Calendar.setfirstweekday` and
49+
:meth:`~Calendar.getfirstweekday` respectively.
50+
51+
.. method:: getfirstweekday()
52+
53+
Return an :class:`int` for the current first weekday (0--6).
54+
55+
Identical to reading the :attr:`~Calendar.firstweekday` property.
56+
57+
.. method:: setfirstweekday(firstweekday)
58+
59+
Set the first weekday to *firstweekday*, passed as an :class:`int` (0--6)
60+
61+
Identical to setting the :attr:`~Calendar.firstweekday` property.
4262

4363
.. method:: iterweekdays()
4464

4565
Return an iterator for the week day numbers that will be used for one
4666
week. The first value from the iterator will be the same as the value of
47-
the :attr:`firstweekday` property.
67+
the :attr:`~Calendar.firstweekday` property.
4868

4969

5070
.. method:: itermonthdates(year, month)
@@ -138,29 +158,69 @@ interpreted as prescribed by the ISO 8601 standard. Year 0 is 1 BC, year -1 is
138158

139159
:class:`TextCalendar` instances have the following methods:
140160

141-
.. method:: formatweek(theweek, w=0)
161+
162+
.. method:: formatday(theday, weekday, width)
163+
164+
Return a string representing a single day formatted with the given *width*.
165+
If *theday* is ``0``, return a string of spaces of
166+
the specified width, representing an empty day. The *weekday* parameter
167+
is unused.
168+
169+
.. method:: formatweek(theweek, w=0, highlight_day=None)
142170

143171
Return a single week in a string with no newline. If *w* is provided, it
144172
specifies the width of the date columns, which are centered. Depends
145173
on the first weekday as specified in the constructor or set by the
146174
:meth:`setfirstweekday` method.
147175

176+
.. versionchanged:: next
177+
If *highlight_day* is given, this date is highlighted in color.
178+
This can be :ref:`controlled using environment variables
179+
<using-on-controlling-color>`.
148180

149-
.. method:: formatmonth(theyear, themonth, w=0, l=0)
181+
182+
.. method:: formatweekday(weekday, width)
183+
184+
Return a string representing the name of a single weekday formatted to
185+
the specified *width*. The *weekday* parameter is an integer representing
186+
the day of the week, where ``0`` is Monday and ``6`` is Sunday.
187+
188+
189+
.. method:: formatweekheader(width)
190+
191+
Return a string containing the header row of weekday names, formatted
192+
with the given *width* for each column. The names depend on the locale
193+
settings and are padded to the specified width.
194+
195+
196+
.. method:: formatmonth(theyear, themonth, w=0, l=0, highlight_day=None)
150197

151198
Return a month's calendar in a multi-line string. If *w* is provided, it
152199
specifies the width of the date columns, which are centered. If *l* is
153200
given, it specifies the number of lines that each week will use. Depends
154201
on the first weekday as specified in the constructor or set by the
155202
:meth:`setfirstweekday` method.
156203

204+
.. versionchanged:: next
205+
If *highlight_day* is given, this date is highlighted in color.
206+
This can be :ref:`controlled using environment variables
207+
<using-on-controlling-color>`.
208+
209+
210+
.. method:: formatmonthname(theyear, themonth, width=0, withyear=True)
211+
212+
Return a string representing the month's name centered within the
213+
specified *width*. If *withyear* is ``True``, include the year in the
214+
output. The *theyear* and *themonth* parameters specify the year
215+
and month for the name to be formatted respectively.
216+
157217

158218
.. method:: prmonth(theyear, themonth, w=0, l=0)
159219

160220
Print a month's calendar as returned by :meth:`formatmonth`.
161221

162222

163-
.. method:: formatyear(theyear, w=2, l=1, c=6, m=3)
223+
.. method:: formatyear(theyear, w=2, l=1, c=6, m=3, highlight_day=None)
164224

165225
Return a *m*-column calendar for an entire year as a multi-line string.
166226
Optional parameters *w*, *l*, and *c* are for date column width, lines per
@@ -169,6 +229,11 @@ interpreted as prescribed by the ISO 8601 standard. Year 0 is 1 BC, year -1 is
169229
:meth:`setfirstweekday` method. The earliest year for which a calendar
170230
can be generated is platform-dependent.
171231

232+
.. versionchanged:: next
233+
If *highlight_day* is given, this date is highlighted in color.
234+
This can be :ref:`controlled using environment variables
235+
<using-on-controlling-color>`.
236+
172237

173238
.. method:: pryear(theyear, w=2, l=1, c=6, m=3)
174239

@@ -445,7 +510,7 @@ The :mod:`calendar` module exports the following data attributes:
445510

446511
A sequence that represents the months of the year in the current locale. This
447512
follows normal convention of January being month number 1, so it has a length of
448-
13 and ``month_name[0]`` is the empty string.
513+
13 and ``month_name[0]`` is the empty string.
449514

450515
>>> import calendar
451516
>>> list(calendar.month_name)
@@ -524,7 +589,7 @@ The :mod:`calendar` module defines the following exceptions:
524589

525590
.. _calendar-cli:
526591

527-
Command-Line Usage
592+
Command-line usage
528593
------------------
529594

530595
.. versionadded:: 2.5
@@ -662,6 +727,9 @@ The following options are accepted:
662727
The number of months printed per row.
663728
Defaults to 3.
664729

730+
.. versionchanged:: next
731+
By default, today's date is highlighted in color and can be
732+
:ref:`controlled using environment variables <using-on-controlling-color>`.
665733

666734
*HTML-mode options:*
667735

0 commit comments

Comments
 (0)