Skip to content

Commit

Permalink
Merge branch 'main' into run-test-suite-with-warnings-as-error
Browse files Browse the repository at this point in the history
  • Loading branch information
graingert authored Jan 14, 2025
2 parents 4b560ef + 99327d1 commit c38898d
Show file tree
Hide file tree
Showing 79 changed files with 2,234 additions and 588 deletions.
17 changes: 16 additions & 1 deletion .github/workflows/reusable-change-detection.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,22 @@ jobs:
# into the PR branch anyway.
#
# https://github.com/python/core-workflow/issues/373
git diff --name-only "origin/$GITHUB_BASE_REF.." | grep -qvE '(\.rst$|^Doc|^Misc|^\.pre-commit-config\.yaml$|\.ruff\.toml$|\.md$|mypy\.ini$)' && echo "run-tests=true" >> "$GITHUB_OUTPUT" || true
grep_ignore_args=(
# file extensions
-e '\.md$'
-e '\.rst$'
# top-level folders
-e '^Doc/'
-e '^Misc/'
# configuration files
-e '^\.github/CODEOWNERS$'
-e '^\.pre-commit-config\.yaml$'
-e '\.ruff\.toml$'
-e 'mypy\.ini$'
)
git diff --name-only "origin/$GITHUB_BASE_REF.." \
| grep -qvE "${grep_ignore_args[@]}" \
&& echo "run-tests=true" >> "$GITHUB_OUTPUT" || true
fi
# Check if we should run hypothesis tests
Expand Down
30 changes: 30 additions & 0 deletions Doc/library/ctypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,36 @@ invalid non-\ ``NULL`` pointers would crash Python)::
ValueError: NULL pointer access
>>>

.. _ctypes-thread-safety:

Thread safety without the GIL
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

In Python 3.13, the :term:`GIL` may be disabled on :term:`experimental free threaded <free threading>` builds.
In ctypes, reads and writes to a single object concurrently is safe, but not across multiple objects:

.. code-block:: pycon
>>> number = c_int(42)
>>> pointer_a = pointer(number)
>>> pointer_b = pointer(number)
In the above, it's only safe for one object to read and write to the address at once if the GIL is disabled.
So, ``pointer_a`` can be shared and written to across multiple threads, but only if ``pointer_b``
is not also attempting to do the same. If this is an issue, consider using a :class:`threading.Lock`
to synchronize access to memory:

.. code-block:: pycon
>>> import threading
>>> lock = threading.Lock()
>>> # Thread 1
>>> with lock:
... pointer_a.contents = 24
>>> # Thread 2
>>> with lock:
... pointer_b.contents = 42
.. _ctypes-type-conversions:

Expand Down
18 changes: 12 additions & 6 deletions Doc/library/fnmatch.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,15 @@ module. See module :mod:`glob` for pathname expansion (:mod:`glob` uses
a period are not special for this module, and are matched by the ``*`` and ``?``
patterns.

Also note that :func:`functools.lru_cache` with the *maxsize* of 32768 is used to
cache the compiled regex patterns in the following functions: :func:`fnmatch`,
:func:`fnmatchcase`, :func:`.filter`.
Unless stated otherwise, "filename string" and "pattern string" either refer to
:class:`str` or ``ISO-8859-1`` encoded :class:`bytes` objects. Note that the
functions documented below do not allow to mix a :class:`!bytes` pattern with
a :class:`!str` filename, and vice-versa.

Finally, note that :func:`functools.lru_cache` with a *maxsize* of 32768
is used to cache the (typed) compiled regex patterns in the following
functions: :func:`fnmatch`, :func:`fnmatchcase`, :func:`.filter`.


.. function:: fnmatch(name, pat)

Expand Down Expand Up @@ -78,16 +84,16 @@ cache the compiled regex patterns in the following functions: :func:`fnmatch`,

.. function:: filter(names, pat)

Construct a list from those elements of the :term:`iterable` *names*
that match pattern *pat*.
Construct a list from those elements of the :term:`iterable` of filename
strings *names* that match the pattern string *pat*.
It is the same as ``[n for n in names if fnmatch(n, pat)]``,
but implemented more efficiently.


.. function:: translate(pat)

Return the shell-style pattern *pat* converted to a regular expression for
using with :func:`re.match`.
using with :func:`re.match`. The pattern is expected to be a :class:`str`.

Example:

Expand Down
94 changes: 94 additions & 0 deletions Doc/library/stdtypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1548,6 +1548,100 @@ objects that compare equal might have different :attr:`~range.start`,
single: str (built-in class); (see also string)
pair: object; string

.. _text-methods-summary:

Text and Binary Sequence Type Methods Summary
=============================================
The following table summarizes the text and binary sequence types methods by
category.


+--------------------------+-------------------------------------------+---------------------------------------------------+
| Category | :class:`str` methods | :class:`bytes` and :class:`bytearray` methods |
+==========================+===========================================+===================================================+
| Formatting | :meth:`str.format` | |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.format_map` | |
| +-------------------------------------------+---------------------------------------------------+
| | :ref:`f-strings` | |
| +-------------------------------------------+---------------------------------------------------+
| | :ref:`old-string-formatting` | :ref:`bytes-formatting` |
+--------------------------+------------------+------------------------+--------------------+------------------------------+
| Searching and Replacing | :meth:`str.find` | :meth:`str.rfind` | :meth:`bytes.find` | :meth:`bytes.rfind` |
| +------------------+------------------------+--------------------+------------------------------+
| | :meth:`str.index`| :meth:`str.rindex` | :meth:`bytes.index`| :meth:`bytes.rindex` |
| +------------------+------------------------+--------------------+------------------------------+
| | :meth:`str.startswith` | :meth:`bytes.startswith` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.endswith` | :meth:`bytes.endswith` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.count` | :meth:`bytes.count` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.replace` | :meth:`bytes.replace` |
+--------------------------+-------------------+-----------------------+---------------------+-----------------------------+
| Splitting and Joining | :meth:`str.split` | :meth:`str.rsplit` | :meth:`bytes.split` | :meth:`bytes.rsplit` |
| +-------------------+-----------------------+---------------------+-----------------------------+
| | :meth:`str.splitlines` | :meth:`bytes.splitlines` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.partition` | :meth:`bytes.partition` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.rpartition` | :meth:`bytes.rpartition` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.join` | :meth:`bytes.join` |
+--------------------------+-------------------------------------------+---------------------------------------------------+
| String Classification | :meth:`str.isalpha` | :meth:`bytes.isalpha` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.isdecimal` | |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.isdigit` | :meth:`bytes.isdigit` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.isnumeric` | |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.isalnum` | :meth:`bytes.isalnum` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.isidentifier` | |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.islower` | :meth:`bytes.islower` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.isupper` | :meth:`bytes.isupper` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.istitle` | :meth:`bytes.istitle` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.isspace` | :meth:`bytes.isspace` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.isprintable` | |
+--------------------------+-------------------------------------------+---------------------------------------------------+
| Case Manipulation | :meth:`str.lower` | :meth:`bytes.lower` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.upper` | :meth:`bytes.upper` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.casefold` | |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.capitalize` | :meth:`bytes.capitalize` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.title` | :meth:`bytes.title` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.swapcase` | :meth:`bytes.swapcase` |
+--------------------------+-------------------+-----------------------+---------------------+-----------------------------+
| Padding and Stripping | :meth:`str.ljust` | :meth:`str.rjust` | :meth:`bytes.ljust` | :meth:`bytes.rjust` |
| +-------------------+-----------------------+---------------------+-----------------------------+
| | :meth:`str.center` | :meth:`bytes.center` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.expandtabs` | :meth:`bytes.expandtabs` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.strip` | :meth:`bytes.strip` |
| +--------------------+----------------------+----------------------+----------------------------+
| | :meth:`str.lstrip` | :meth:`str.rstrip` | :meth:`bytes.lstrip` | :meth:`bytes.rstrip` |
+--------------------------+--------------------+----------------------+----------------------+----------------------------+
| Translation and Encoding | :meth:`str.translate` | :meth:`bytes.translate` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.maketrans` | :meth:`bytes.maketrans` |
| +-------------------------------------------+---------------------------------------------------+
| | :meth:`str.encode` | |
| +-------------------------------------------+---------------------------------------------------+
| | | :meth:`bytes.decode` |
+--------------------------+-------------------------------------------+---------------------------------------------------+

.. _textseq:

Text Sequence Type --- :class:`str`
Expand Down
61 changes: 61 additions & 0 deletions Doc/library/unittest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,12 @@ Test cases
| :meth:`assertNotIsInstance(a, b) | ``not isinstance(a, b)`` | 3.2 |
| <TestCase.assertNotIsInstance>` | | |
+-----------------------------------------+-----------------------------+---------------+
| :meth:`assertIsSubclass(a, b) | ``issubclass(a, b)`` | 3.14 |
| <TestCase.assertIsSubclass>` | | |
+-----------------------------------------+-----------------------------+---------------+
| :meth:`assertNotIsSubclass(a, b) | ``not issubclass(a, b)`` | 3.14 |
| <TestCase.assertNotIsSubclass>` | | |
+-----------------------------------------+-----------------------------+---------------+

All the assert methods accept a *msg* argument that, if specified, is used
as the error message on failure (see also :data:`longMessage`).
Expand Down Expand Up @@ -961,6 +967,15 @@ Test cases
.. versionadded:: 3.2


.. method:: assertIsSubclass(cls, superclass, msg=None)
assertNotIsSubclass(cls, superclass, msg=None)

Test that *cls* is (or is not) a subclass of *superclass* (which can be a
class or a tuple of classes, as supported by :func:`issubclass`).
To check for the exact type, use :func:`assertIs(cls, superclass) <assertIs>`.

.. versionadded:: next


It is also possible to check the production of exceptions, warnings, and
log messages using the following methods:
Expand Down Expand Up @@ -1210,6 +1225,24 @@ Test cases
| <TestCase.assertCountEqual>` | elements in the same number, | |
| | regardless of their order. | |
+---------------------------------------+--------------------------------+--------------+
| :meth:`assertStartsWith(a, b) | ``a.startswith(b)`` | 3.14 |
| <TestCase.assertStartsWith>` | | |
+---------------------------------------+--------------------------------+--------------+
| :meth:`assertNotStartsWith(a, b) | ``not a.startswith(b)`` | 3.14 |
| <TestCase.assertNotStartsWith>` | | |
+---------------------------------------+--------------------------------+--------------+
| :meth:`assertEndsWith(a, b) | ``a.endswith(b)`` | 3.14 |
| <TestCase.assertEndsWith>` | | |
+---------------------------------------+--------------------------------+--------------+
| :meth:`assertNotEndsWith(a, b) | ``not a.endswith(b)`` | 3.14 |
| <TestCase.assertNotEndsWith>` | | |
+---------------------------------------+--------------------------------+--------------+
| :meth:`assertHasAttr(a, b) | ``hastattr(a, b)`` | 3.14 |
| <TestCase.assertHasAttr>` | | |
+---------------------------------------+--------------------------------+--------------+
| :meth:`assertNotHasAttr(a, b) | ``not hastattr(a, b)`` | 3.14 |
| <TestCase.assertNotHasAttr>` | | |
+---------------------------------------+--------------------------------+--------------+


.. method:: assertAlmostEqual(first, second, places=7, msg=None, delta=None)
Expand Down Expand Up @@ -1279,6 +1312,34 @@ Test cases
.. versionadded:: 3.2


.. method:: assertStartsWith(s, prefix, msg=None)
.. method:: assertNotStartsWith(s, prefix, msg=None)

Test that the Unicode or byte string *s* starts (or does not start)
with a *prefix*.
*prefix* can also be a tuple of strings to try.

.. versionadded:: next


.. method:: assertEndsWith(s, suffix, msg=None)
.. method:: assertNotEndsWith(s, suffix, msg=None)

Test that the Unicode or byte string *s* ends (or does not end)
with a *suffix*.
*suffix* can also be a tuple of strings to try.

.. versionadded:: next


.. method:: assertHasAttr(obj, name, msg=None)
.. method:: assertNotHasAttr(obj, name, msg=None)

Test that the object *obj* has (or has not) an attribute *name*.

.. versionadded:: next


.. _type-specific-methods:

The :meth:`assertEqual` method dispatches the equality check for objects of
Expand Down
Loading

0 comments on commit c38898d

Please sign in to comment.