Skip to content

Commit f633fa5

Browse files
authored
Merge branch 'main' into fix_contains_error
2 parents 9e26bff + 4e8aa32 commit f633fa5

File tree

73 files changed

+1692
-1564
lines changed

Some content is hidden

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

73 files changed

+1692
-1564
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ jobs:
199199
uses: ./.github/workflows/reusable-macos.yml
200200
with:
201201
config_hash: ${{ needs.check_source.outputs.config_hash }}
202-
# macos-14 is M1, macos-13 is Intel
203-
os-matrix: '["macos-14", "macos-13"]'
202+
# Cirrus is M1, macos-13 is default GHA Intel
203+
os-matrix: '["ghcr.io/cirruslabs/macos-runner:sonoma", "macos-13"]'
204204

205205
build_macos_free_threading:
206206
name: 'macOS (free-threading)'
@@ -210,8 +210,8 @@ jobs:
210210
with:
211211
config_hash: ${{ needs.check_source.outputs.config_hash }}
212212
free-threading: true
213-
# macos-14-large is Intel with 12 cores (most parallelism)
214-
os-matrix: '["macos-14"]'
213+
# Cirrus is M1
214+
os-matrix: '["ghcr.io/cirruslabs/macos-runner:sonoma"]'
215215

216216
build_ubuntu:
217217
name: 'Ubuntu'

Doc/c-api/long.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,19 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate.
494494
.. versionadded:: 3.13
495495
496496
497+
.. c:function:: int PyLong_GetSign(PyObject *obj, int *sign)
498+
499+
Get the sign of the integer object *obj*.
500+
501+
On success, set *\*sign* to the integer sign (0, -1 or +1 for zero, negative or
502+
positive integer, respectively) and return 0.
503+
504+
On failure, return -1 with an exception set. This function always succeeds
505+
if *obj* is a :c:type:`PyLongObject` or its subtype.
506+
507+
.. versionadded:: 3.14
508+
509+
497510
.. c:function:: int PyUnstable_Long_IsCompact(const PyLongObject* op)
498511
499512
Return 1 if *op* is compact, 0 otherwise.

Doc/c-api/monitoring.rst

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

33
.. _monitoring:
44

5-
Monitorong C API
5+
Monitoring C API
66
================
77

88
Added in version 3.13.

Doc/c-api/reflection.rst

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,28 @@ Reflection
1919
2020
.. deprecated:: 3.13
2121
22-
To avoid creating a reference cycle in :term:`optimized scopes <optimized scope>`,
23-
use either :c:func:`PyEval_GetFrameLocals` to obtain the same behaviour as calling
22+
Use either :c:func:`PyEval_GetFrameLocals` to obtain the same behaviour as calling
2423
:func:`locals` in Python code, or else call :c:func:`PyFrame_GetLocals` on the result
25-
of :c:func:`PyEval_GetFrame` to get the same result as this function without having to
26-
cache the proxy instance on the underlying frame.
24+
of :c:func:`PyEval_GetFrame` to access the :attr:`~frame.f_locals` attribute of the
25+
currently executing frame.
2726
28-
Return the :attr:`~frame.f_locals` attribute of the currently executing frame,
27+
Return a mapping providing access to the local variables in the current execution frame,
2928
or ``NULL`` if no frame is currently executing.
3029
31-
If the frame refers to an :term:`optimized scope`, this returns a
32-
write-through proxy object that allows modifying the locals.
33-
In all other cases (classes, modules, :func:`exec`, :func:`eval`) it returns
34-
the mapping representing the frame locals directly (as described for
35-
:func:`locals`).
30+
Refer to :func:`locals` for details of the mapping returned at different scopes.
31+
32+
As this function returns a :term:`borrowed reference`, the dictionary returned for
33+
:term:`optimized scopes <optimized scope>` is cached on the frame object and will remain
34+
alive as long as the frame object does. Unlike :c:func:`PyEval_GetFrameLocals` and
35+
:func:`locals`, subsequent calls to this function in the same frame will update the
36+
contents of the cached dictionary to reflect changes in the state of the local variables
37+
rather than returning a new snapshot.
3638
3739
.. versionchanged:: 3.13
38-
As part of :pep:`667`, return a proxy object for optimized scopes.
40+
As part of :pep:`667`, :c:func:`PyFrame_GetLocals`, :func:`locals`, and
41+
:attr:`FrameType.f_locals <frame.f_locals>` no longer make use of the shared cache
42+
dictionary. Refer to the :ref:`What's New entry <whatsnew313-locals-semantics>` for
43+
additional details.
3944
4045
4146
.. c:function:: PyObject* PyEval_GetGlobals(void)

Doc/howto/logging-cookbook.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2950,7 +2950,7 @@ When run, this produces a file with exactly two lines:
29502950
.. code-block:: none
29512951
29522952
28/01/2015 07:21:23|INFO|Sample message|
2953-
28/01/2015 07:21:23|ERROR|ZeroDivisionError: integer division or modulo by zero|'Traceback (most recent call last):\n File "logtest7.py", line 30, in main\n x = 1 / 0\nZeroDivisionError: integer division or modulo by zero'|
2953+
28/01/2015 07:21:23|ERROR|ZeroDivisionError: division by zero|'Traceback (most recent call last):\n File "logtest7.py", line 30, in main\n x = 1 / 0\nZeroDivisionError: division by zero'|
29542954
29552955
While the above treatment is simplistic, it points the way to how exception
29562956
information can be formatted to your liking. The :mod:`traceback` module may be

Doc/library/functions.rst

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,9 +1004,8 @@ are always available. They are listed here in alphabetical order.
10041004
115
10051005

10061006
If the argument defines :meth:`~object.__int__`,
1007-
``int(x)`` returns ``x.__int__()``. If the argument defines :meth:`~object.__index__`,
1008-
it returns ``x.__index__()``. If the argument defines :meth:`~object.__trunc__`,
1009-
it returns ``x.__trunc__()``.
1007+
``int(x)`` returns ``x.__int__()``. If the argument defines
1008+
:meth:`~object.__index__`, it returns ``x.__index__()``.
10101009
For floating point numbers, this truncates towards zero.
10111010

10121011
If the argument is not a number or if *base* is given, then it must be a string,
@@ -1044,9 +1043,6 @@ are always available. They are listed here in alphabetical order.
10441043
.. versionchanged:: 3.8
10451044
Falls back to :meth:`~object.__index__` if :meth:`~object.__int__` is not defined.
10461045

1047-
.. versionchanged:: 3.11
1048-
The delegation to :meth:`~object.__trunc__` is deprecated.
1049-
10501046
.. versionchanged:: 3.11
10511047
:class:`int` string inputs and string representations can be limited to
10521048
help avoid denial of service attacks. A :exc:`ValueError` is raised when
@@ -1055,6 +1051,9 @@ are always available. They are listed here in alphabetical order.
10551051
See the :ref:`integer string conversion length limitation
10561052
<int_max_str_digits>` documentation.
10571053

1054+
.. versionchanged:: 3.14
1055+
:func:`int` no longer delegates to the :meth:`~object.__trunc__` method.
1056+
10581057
.. function:: isinstance(object, classinfo)
10591058

10601059
Return ``True`` if the *object* argument is an instance of the *classinfo*

Doc/library/pathlib.rst

Lines changed: 84 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,90 @@ Querying file type and status
10671067
.. versionadded:: 3.5
10681068

10691069

1070+
Reading and writing files
1071+
^^^^^^^^^^^^^^^^^^^^^^^^^
1072+
1073+
1074+
.. method:: Path.open(mode='r', buffering=-1, encoding=None, errors=None, newline=None)
1075+
1076+
Open the file pointed to by the path, like the built-in :func:`open`
1077+
function does::
1078+
1079+
>>> p = Path('setup.py')
1080+
>>> with p.open() as f:
1081+
... f.readline()
1082+
...
1083+
'#!/usr/bin/env python3\n'
1084+
1085+
1086+
.. method:: Path.read_text(encoding=None, errors=None, newline=None)
1087+
1088+
Return the decoded contents of the pointed-to file as a string::
1089+
1090+
>>> p = Path('my_text_file')
1091+
>>> p.write_text('Text file contents')
1092+
18
1093+
>>> p.read_text()
1094+
'Text file contents'
1095+
1096+
The file is opened and then closed. The optional parameters have the same
1097+
meaning as in :func:`open`.
1098+
1099+
.. versionadded:: 3.5
1100+
1101+
.. versionchanged:: 3.13
1102+
The *newline* parameter was added.
1103+
1104+
1105+
.. method:: Path.read_bytes()
1106+
1107+
Return the binary contents of the pointed-to file as a bytes object::
1108+
1109+
>>> p = Path('my_binary_file')
1110+
>>> p.write_bytes(b'Binary file contents')
1111+
20
1112+
>>> p.read_bytes()
1113+
b'Binary file contents'
1114+
1115+
.. versionadded:: 3.5
1116+
1117+
1118+
.. method:: Path.write_text(data, encoding=None, errors=None, newline=None)
1119+
1120+
Open the file pointed to in text mode, write *data* to it, and close the
1121+
file::
1122+
1123+
>>> p = Path('my_text_file')
1124+
>>> p.write_text('Text file contents')
1125+
18
1126+
>>> p.read_text()
1127+
'Text file contents'
1128+
1129+
An existing file of the same name is overwritten. The optional parameters
1130+
have the same meaning as in :func:`open`.
1131+
1132+
.. versionadded:: 3.5
1133+
1134+
.. versionchanged:: 3.10
1135+
The *newline* parameter was added.
1136+
1137+
1138+
.. method:: Path.write_bytes(data)
1139+
1140+
Open the file pointed to in bytes mode, write *data* to it, and close the
1141+
file::
1142+
1143+
>>> p = Path('my_binary_file')
1144+
>>> p.write_bytes(b'Binary file contents')
1145+
20
1146+
>>> p.read_bytes()
1147+
b'Binary file contents'
1148+
1149+
An existing file of the same name is overwritten.
1150+
1151+
.. versionadded:: 3.5
1152+
1153+
10701154
Other methods
10711155
^^^^^^^^^^^^^
10721156

@@ -1360,18 +1444,6 @@ example because the path doesn't exist).
13601444
The *exist_ok* parameter was added.
13611445

13621446

1363-
.. method:: Path.open(mode='r', buffering=-1, encoding=None, errors=None, newline=None)
1364-
1365-
Open the file pointed to by the path, like the built-in :func:`open`
1366-
function does::
1367-
1368-
>>> p = Path('setup.py')
1369-
>>> with p.open() as f:
1370-
... f.readline()
1371-
...
1372-
'#!/usr/bin/env python3\n'
1373-
1374-
13751447
.. method:: Path.owner(*, follow_symlinks=True)
13761448

13771449
Return the name of the user owning the file. :exc:`KeyError` is raised
@@ -1388,37 +1460,6 @@ example because the path doesn't exist).
13881460
The *follow_symlinks* parameter was added.
13891461

13901462

1391-
.. method:: Path.read_bytes()
1392-
1393-
Return the binary contents of the pointed-to file as a bytes object::
1394-
1395-
>>> p = Path('my_binary_file')
1396-
>>> p.write_bytes(b'Binary file contents')
1397-
20
1398-
>>> p.read_bytes()
1399-
b'Binary file contents'
1400-
1401-
.. versionadded:: 3.5
1402-
1403-
1404-
.. method:: Path.read_text(encoding=None, errors=None, newline=None)
1405-
1406-
Return the decoded contents of the pointed-to file as a string::
1407-
1408-
>>> p = Path('my_text_file')
1409-
>>> p.write_text('Text file contents')
1410-
18
1411-
>>> p.read_text()
1412-
'Text file contents'
1413-
1414-
The file is opened and then closed. The optional parameters have the same
1415-
meaning as in :func:`open`.
1416-
1417-
.. versionadded:: 3.5
1418-
1419-
.. versionchanged:: 3.13
1420-
The *newline* parameter was added.
1421-
14221463
.. method:: Path.readlink()
14231464

14241465
Return the path to which the symbolic link points (as returned by
@@ -1593,42 +1634,6 @@ example because the path doesn't exist).
15931634
The *missing_ok* parameter was added.
15941635

15951636

1596-
.. method:: Path.write_bytes(data)
1597-
1598-
Open the file pointed to in bytes mode, write *data* to it, and close the
1599-
file::
1600-
1601-
>>> p = Path('my_binary_file')
1602-
>>> p.write_bytes(b'Binary file contents')
1603-
20
1604-
>>> p.read_bytes()
1605-
b'Binary file contents'
1606-
1607-
An existing file of the same name is overwritten.
1608-
1609-
.. versionadded:: 3.5
1610-
1611-
1612-
.. method:: Path.write_text(data, encoding=None, errors=None, newline=None)
1613-
1614-
Open the file pointed to in text mode, write *data* to it, and close the
1615-
file::
1616-
1617-
>>> p = Path('my_text_file')
1618-
>>> p.write_text('Text file contents')
1619-
18
1620-
>>> p.read_text()
1621-
'Text file contents'
1622-
1623-
An existing file of the same name is overwritten. The optional parameters
1624-
have the same meaning as in :func:`open`.
1625-
1626-
.. versionadded:: 3.5
1627-
1628-
.. versionchanged:: 3.10
1629-
The *newline* parameter was added.
1630-
1631-
16321637
.. _pathlib-pattern-language:
16331638

16341639
Pattern language

Doc/library/typing.rst

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3080,35 +3080,37 @@ Introspection helpers
30803080
Return a dictionary containing type hints for a function, method, module
30813081
or class object.
30823082

3083-
This is often the same as ``obj.__annotations__``. In addition,
3084-
forward references encoded as string literals are handled by evaluating
3085-
them in ``globals``, ``locals`` and (where applicable)
3086-
:ref:`type parameter <type-params>` namespaces.
3087-
For a class ``C``, return
3088-
a dictionary constructed by merging all the ``__annotations__`` along
3089-
``C.__mro__`` in reverse order.
3090-
3091-
The function recursively replaces all ``Annotated[T, ...]`` with ``T``,
3092-
unless ``include_extras`` is set to ``True`` (see :class:`Annotated` for
3093-
more information). For example:
3094-
3095-
.. testcode::
3096-
3097-
class Student(NamedTuple):
3098-
name: Annotated[str, 'some marker']
3099-
3100-
assert get_type_hints(Student) == {'name': str}
3101-
assert get_type_hints(Student, include_extras=False) == {'name': str}
3102-
assert get_type_hints(Student, include_extras=True) == {
3103-
'name': Annotated[str, 'some marker']
3104-
}
3083+
This is often the same as ``obj.__annotations__``, but this function makes
3084+
the following changes to the annotations dictionary:
3085+
3086+
* Forward references encoded as string literals or :class:`ForwardRef`
3087+
objects are handled by evaluating them in *globalns*, *localns*, and
3088+
(where applicable) *obj*'s :ref:`type parameter <type-params>` namespace.
3089+
If *globalns* or *localns* is not given, appropriate namespace
3090+
dictionaries are inferred from *obj*.
3091+
* ``None`` is replaced with :class:`types.NoneType`.
3092+
* If :func:`@no_type_check <no_type_check>` has been applied to *obj*, an
3093+
empty dictionary is returned.
3094+
* If *obj* is a class ``C``, the function returns a dictionary that merges
3095+
annotations from ``C``'s base classes with those on ``C`` directly. This
3096+
is done by traversing ``C.__mro__`` and iteratively combining
3097+
``__annotations__`` dictionaries. Annotations on classes appearing
3098+
earlier in the :term:`method resolution order` always take precedence over
3099+
annotations on classes appearing later in the method resolution order.
3100+
* The function recursively replaces all occurrences of ``Annotated[T, ...]``
3101+
with ``T``, unless *include_extras* is set to ``True`` (see
3102+
:class:`Annotated` for more information).
3103+
3104+
See also :func:`inspect.get_annotations`, a lower-level function that
3105+
returns annotations more directly.
31053106

31063107
.. note::
31073108

3108-
:func:`get_type_hints` does not work with imported
3109-
:ref:`type aliases <type-aliases>` that include forward references.
3110-
Enabling postponed evaluation of annotations (:pep:`563`) may remove
3111-
the need for most forward references.
3109+
If any forward references in the annotations of *obj* are not resolvable
3110+
or are not valid Python code, this function will raise an exception
3111+
such as :exc:`NameError`. For example, this can happen with imported
3112+
:ref:`type aliases <type-aliases>` that include forward references,
3113+
or with names imported under :data:`if TYPE_CHECKING <TYPE_CHECKING>`.
31123114

31133115
.. versionchanged:: 3.9
31143116
Added ``include_extras`` parameter as part of :pep:`593`.

0 commit comments

Comments
 (0)