Skip to content

Commit

Permalink
Merge branch 'main' into gh-117657-immortalize
Browse files Browse the repository at this point in the history
  • Loading branch information
colesbury authored Jun 3, 2024
2 parents be3ec68 + 41c1cef commit 170299b
Show file tree
Hide file tree
Showing 60 changed files with 705 additions and 462 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ jobs:
uses: ./.github/workflows/reusable-macos.yml
with:
config_hash: ${{ needs.check_source.outputs.config_hash }}
# macos-14 is M1, macos-13 is Intel
os-matrix: '["macos-14", "macos-13"]'
# Cirrus is M1, macos-13 is default GHA Intel
os-matrix: '["ghcr.io/cirruslabs/macos-runner:sonoma", "macos-13"]'

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

build_ubuntu:
name: 'Ubuntu'
Expand Down
13 changes: 13 additions & 0 deletions Doc/c-api/long.rst
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,19 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate.
.. versionadded:: 3.13
.. c:function:: int PyLong_GetSign(PyObject *obj, int *sign)
Get the sign of the integer object *obj*.
On success, set *\*sign* to the integer sign (0, -1 or +1 for zero, negative or
positive integer, respectively) and return 0.
On failure, return -1 with an exception set. This function always succeeds
if *obj* is a :c:type:`PyLongObject` or its subtype.
.. versionadded:: 3.14
.. c:function:: int PyUnstable_Long_IsCompact(const PyLongObject* op)
Return 1 if *op* is compact, 0 otherwise.
Expand Down
2 changes: 1 addition & 1 deletion Doc/c-api/monitoring.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

.. _monitoring:

Monitorong C API
Monitoring C API
================

Added in version 3.13.
Expand Down
2 changes: 1 addition & 1 deletion Doc/howto/logging-cookbook.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2950,7 +2950,7 @@ When run, this produces a file with exactly two lines:
.. code-block:: none
28/01/2015 07:21:23|INFO|Sample message|
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'|
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'|
While the above treatment is simplistic, it points the way to how exception
information can be formatted to your liking. The :mod:`traceback` module may be
Expand Down
163 changes: 84 additions & 79 deletions Doc/library/pathlib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1067,6 +1067,90 @@ Querying file type and status
.. versionadded:: 3.5


Reading and writing files
^^^^^^^^^^^^^^^^^^^^^^^^^


.. method:: Path.open(mode='r', buffering=-1, encoding=None, errors=None, newline=None)

Open the file pointed to by the path, like the built-in :func:`open`
function does::

>>> p = Path('setup.py')
>>> with p.open() as f:
... f.readline()
...
'#!/usr/bin/env python3\n'


.. method:: Path.read_text(encoding=None, errors=None, newline=None)

Return the decoded contents of the pointed-to file as a string::

>>> p = Path('my_text_file')
>>> p.write_text('Text file contents')
18
>>> p.read_text()
'Text file contents'

The file is opened and then closed. The optional parameters have the same
meaning as in :func:`open`.

.. versionadded:: 3.5

.. versionchanged:: 3.13
The *newline* parameter was added.


.. method:: Path.read_bytes()

Return the binary contents of the pointed-to file as a bytes object::

>>> p = Path('my_binary_file')
>>> p.write_bytes(b'Binary file contents')
20
>>> p.read_bytes()
b'Binary file contents'

.. versionadded:: 3.5


.. method:: Path.write_text(data, encoding=None, errors=None, newline=None)

Open the file pointed to in text mode, write *data* to it, and close the
file::

>>> p = Path('my_text_file')
>>> p.write_text('Text file contents')
18
>>> p.read_text()
'Text file contents'

An existing file of the same name is overwritten. The optional parameters
have the same meaning as in :func:`open`.

.. versionadded:: 3.5

.. versionchanged:: 3.10
The *newline* parameter was added.


.. method:: Path.write_bytes(data)

Open the file pointed to in bytes mode, write *data* to it, and close the
file::

>>> p = Path('my_binary_file')
>>> p.write_bytes(b'Binary file contents')
20
>>> p.read_bytes()
b'Binary file contents'

An existing file of the same name is overwritten.

.. versionadded:: 3.5


Other methods
^^^^^^^^^^^^^

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


.. method:: Path.open(mode='r', buffering=-1, encoding=None, errors=None, newline=None)

Open the file pointed to by the path, like the built-in :func:`open`
function does::

>>> p = Path('setup.py')
>>> with p.open() as f:
... f.readline()
...
'#!/usr/bin/env python3\n'


.. method:: Path.owner(*, follow_symlinks=True)

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


.. method:: Path.read_bytes()

Return the binary contents of the pointed-to file as a bytes object::

>>> p = Path('my_binary_file')
>>> p.write_bytes(b'Binary file contents')
20
>>> p.read_bytes()
b'Binary file contents'

.. versionadded:: 3.5


.. method:: Path.read_text(encoding=None, errors=None, newline=None)

Return the decoded contents of the pointed-to file as a string::

>>> p = Path('my_text_file')
>>> p.write_text('Text file contents')
18
>>> p.read_text()
'Text file contents'

The file is opened and then closed. The optional parameters have the same
meaning as in :func:`open`.

.. versionadded:: 3.5

.. versionchanged:: 3.13
The *newline* parameter was added.

.. method:: Path.readlink()

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


.. method:: Path.write_bytes(data)

Open the file pointed to in bytes mode, write *data* to it, and close the
file::

>>> p = Path('my_binary_file')
>>> p.write_bytes(b'Binary file contents')
20
>>> p.read_bytes()
b'Binary file contents'

An existing file of the same name is overwritten.

.. versionadded:: 3.5


.. method:: Path.write_text(data, encoding=None, errors=None, newline=None)

Open the file pointed to in text mode, write *data* to it, and close the
file::

>>> p = Path('my_text_file')
>>> p.write_text('Text file contents')
18
>>> p.read_text()
'Text file contents'

An existing file of the same name is overwritten. The optional parameters
have the same meaning as in :func:`open`.

.. versionadded:: 3.5

.. versionchanged:: 3.10
The *newline* parameter was added.


.. _pathlib-pattern-language:

Pattern language
Expand Down
54 changes: 28 additions & 26 deletions Doc/library/typing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3080,35 +3080,37 @@ Introspection helpers
Return a dictionary containing type hints for a function, method, module
or class object.

This is often the same as ``obj.__annotations__``. In addition,
forward references encoded as string literals are handled by evaluating
them in ``globals``, ``locals`` and (where applicable)
:ref:`type parameter <type-params>` namespaces.
For a class ``C``, return
a dictionary constructed by merging all the ``__annotations__`` along
``C.__mro__`` in reverse order.

The function recursively replaces all ``Annotated[T, ...]`` with ``T``,
unless ``include_extras`` is set to ``True`` (see :class:`Annotated` for
more information). For example:

.. testcode::

class Student(NamedTuple):
name: Annotated[str, 'some marker']

assert get_type_hints(Student) == {'name': str}
assert get_type_hints(Student, include_extras=False) == {'name': str}
assert get_type_hints(Student, include_extras=True) == {
'name': Annotated[str, 'some marker']
}
This is often the same as ``obj.__annotations__``, but this function makes
the following changes to the annotations dictionary:

* Forward references encoded as string literals or :class:`ForwardRef`
objects are handled by evaluating them in *globalns*, *localns*, and
(where applicable) *obj*'s :ref:`type parameter <type-params>` namespace.
If *globalns* or *localns* is not given, appropriate namespace
dictionaries are inferred from *obj*.
* ``None`` is replaced with :class:`types.NoneType`.
* If :func:`@no_type_check <no_type_check>` has been applied to *obj*, an
empty dictionary is returned.
* If *obj* is a class ``C``, the function returns a dictionary that merges
annotations from ``C``'s base classes with those on ``C`` directly. This
is done by traversing ``C.__mro__`` and iteratively combining
``__annotations__`` dictionaries. Annotations on classes appearing
earlier in the :term:`method resolution order` always take precedence over
annotations on classes appearing later in the method resolution order.
* The function recursively replaces all occurrences of ``Annotated[T, ...]``
with ``T``, unless *include_extras* is set to ``True`` (see
:class:`Annotated` for more information).

See also :func:`inspect.get_annotations`, a lower-level function that
returns annotations more directly.

.. note::

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

.. versionchanged:: 3.9
Added ``include_extras`` parameter as part of :pep:`593`.
Expand Down
9 changes: 9 additions & 0 deletions Doc/library/zipfile.rst
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,15 @@ Path objects are traversable using the ``/`` operator or ``joinpath``.

Return ``True`` if the current context references a file.

.. method:: Path.is_symlink()

Return ``True`` if the current context references a symbolic link.

.. versionadded:: 3.12

.. versionchanged:: 3.12.4
Prior to 3.12.4, ``is_symlink`` would unconditionally return ``False``.

.. method:: Path.exists()

Return ``True`` if the current context references a file or
Expand Down
2 changes: 1 addition & 1 deletion Doc/whatsnew/3.13.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1334,7 +1334,7 @@ PEP 594: dead batteries (and other module removals)
* :mod:`!sunau`.
(Contributed by Victor Stinner in :gh:`104773`.)

* :mod:`!telnetlib`, use the projects :pypi:`telnetlib3 ` or
* :mod:`!telnetlib`, use the projects :pypi:`telnetlib3` or
:pypi:`Exscript` instead.
(Contributed by Victor Stinner in :gh:`104773`.)

Expand Down
10 changes: 10 additions & 0 deletions Doc/whatsnew/3.14.rst
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,13 @@ typing
* Remove :class:`!typing.ByteString`. It had previously raised a
:exc:`DeprecationWarning` since Python 3.12.

urllib
------

* Remove deprecated :class:`!Quoter` class from :mod:`urllib.parse`.
It had previously raised a :exc:`DeprecationWarning` since Python 3.11.
(Contributed by Nikita Sobolev in :gh:`118827`.)

Others
------

Expand Down Expand Up @@ -248,6 +255,9 @@ C API Changes
New Features
------------

* Add :c:func:`PyLong_GetSign` function to get the sign of :class:`int` objects.
(Contributed by Sergey B Kirpichev in :gh:`116560`.)

Porting to Python 3.14
----------------------

Expand Down
3 changes: 2 additions & 1 deletion Include/cpython/dictobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ typedef struct {

PyAPI_FUNC(PyObject *) _PyDict_GetItem_KnownHash(PyObject *mp, PyObject *key,
Py_hash_t hash);
PyAPI_FUNC(PyObject *) _PyDict_GetItemStringWithError(PyObject *, const char *);
// PyDict_GetItemStringRef() can be used instead
Py_DEPRECATED(3.14) PyAPI_FUNC(PyObject *) _PyDict_GetItemStringWithError(PyObject *, const char *);
PyAPI_FUNC(PyObject *) PyDict_SetDefault(
PyObject *mp, PyObject *key, PyObject *defaultobj);

Expand Down
10 changes: 7 additions & 3 deletions Include/cpython/longobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,13 @@ PyAPI_FUNC(PyObject*) PyLong_FromUnsignedNativeBytes(const void* buffer,
PyAPI_FUNC(int) PyUnstable_Long_IsCompact(const PyLongObject* op);
PyAPI_FUNC(Py_ssize_t) PyUnstable_Long_CompactValue(const PyLongObject* op);

// _PyLong_Sign. Return 0 if v is 0, -1 if v < 0, +1 if v > 0.
// v must not be NULL, and must be a normalized long.
// There are no error cases.
/* PyLong_GetSign. Get the sign of an integer object:
0, -1 or +1 for zero, negative or positive integer, respectively.
- On success, set '*sign' to the integer sign, and return 0.
- On failure, set an exception, and return -1. */
PyAPI_FUNC(int) PyLong_GetSign(PyObject *v, int *sign);

PyAPI_FUNC(int) _PyLong_Sign(PyObject *v);

/* _PyLong_NumBits. Return the number of bits needed to represent the
Expand Down
4 changes: 4 additions & 0 deletions InternalDocs/index.md → InternalDocs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ to hold for other implementations of the Python language.
The core dev team attempts to keep this documentation up to date. If
it is not, please report that through the
[issue tracker](https://github.com/python/cpython/issues).


[Exception Handling](exception_handling.md)

Loading

0 comments on commit 170299b

Please sign in to comment.