Skip to content

Commit c38898d

Browse files
authored
Merge branch 'main' into run-test-suite-with-warnings-as-error
2 parents 4b560ef + 99327d1 commit c38898d

File tree

79 files changed

+2234
-588
lines changed

Some content is hidden

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

79 files changed

+2234
-588
lines changed

.github/workflows/reusable-change-detection.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,22 @@ jobs:
8383
# into the PR branch anyway.
8484
#
8585
# https://github.com/python/core-workflow/issues/373
86-
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
86+
grep_ignore_args=(
87+
# file extensions
88+
-e '\.md$'
89+
-e '\.rst$'
90+
# top-level folders
91+
-e '^Doc/'
92+
-e '^Misc/'
93+
# configuration files
94+
-e '^\.github/CODEOWNERS$'
95+
-e '^\.pre-commit-config\.yaml$'
96+
-e '\.ruff\.toml$'
97+
-e 'mypy\.ini$'
98+
)
99+
git diff --name-only "origin/$GITHUB_BASE_REF.." \
100+
| grep -qvE "${grep_ignore_args[@]}" \
101+
&& echo "run-tests=true" >> "$GITHUB_OUTPUT" || true
87102
fi
88103
89104
# Check if we should run hypothesis tests

Doc/library/ctypes.rst

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,36 @@ invalid non-\ ``NULL`` pointers would crash Python)::
870870
ValueError: NULL pointer access
871871
>>>
872872

873+
.. _ctypes-thread-safety:
874+
875+
Thread safety without the GIL
876+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
877+
878+
In Python 3.13, the :term:`GIL` may be disabled on :term:`experimental free threaded <free threading>` builds.
879+
In ctypes, reads and writes to a single object concurrently is safe, but not across multiple objects:
880+
881+
.. code-block:: pycon
882+
883+
>>> number = c_int(42)
884+
>>> pointer_a = pointer(number)
885+
>>> pointer_b = pointer(number)
886+
887+
In the above, it's only safe for one object to read and write to the address at once if the GIL is disabled.
888+
So, ``pointer_a`` can be shared and written to across multiple threads, but only if ``pointer_b``
889+
is not also attempting to do the same. If this is an issue, consider using a :class:`threading.Lock`
890+
to synchronize access to memory:
891+
892+
.. code-block:: pycon
893+
894+
>>> import threading
895+
>>> lock = threading.Lock()
896+
>>> # Thread 1
897+
>>> with lock:
898+
... pointer_a.contents = 24
899+
>>> # Thread 2
900+
>>> with lock:
901+
... pointer_b.contents = 42
902+
873903
874904
.. _ctypes-type-conversions:
875905

Doc/library/fnmatch.rst

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,15 @@ module. See module :mod:`glob` for pathname expansion (:mod:`glob` uses
4646
a period are not special for this module, and are matched by the ``*`` and ``?``
4747
patterns.
4848

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

5359
.. function:: fnmatch(name, pat)
5460

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

7985
.. function:: filter(names, pat)
8086

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

8692

8793
.. function:: translate(pat)
8894

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

9298
Example:
9399

Doc/library/stdtypes.rst

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1548,6 +1548,100 @@ objects that compare equal might have different :attr:`~range.start`,
15481548
single: str (built-in class); (see also string)
15491549
pair: object; string
15501550

1551+
.. _text-methods-summary:
1552+
1553+
Text and Binary Sequence Type Methods Summary
1554+
=============================================
1555+
The following table summarizes the text and binary sequence types methods by
1556+
category.
1557+
1558+
1559+
+--------------------------+-------------------------------------------+---------------------------------------------------+
1560+
| Category | :class:`str` methods | :class:`bytes` and :class:`bytearray` methods |
1561+
+==========================+===========================================+===================================================+
1562+
| Formatting | :meth:`str.format` | |
1563+
| +-------------------------------------------+---------------------------------------------------+
1564+
| | :meth:`str.format_map` | |
1565+
| +-------------------------------------------+---------------------------------------------------+
1566+
| | :ref:`f-strings` | |
1567+
| +-------------------------------------------+---------------------------------------------------+
1568+
| | :ref:`old-string-formatting` | :ref:`bytes-formatting` |
1569+
+--------------------------+------------------+------------------------+--------------------+------------------------------+
1570+
| Searching and Replacing | :meth:`str.find` | :meth:`str.rfind` | :meth:`bytes.find` | :meth:`bytes.rfind` |
1571+
| +------------------+------------------------+--------------------+------------------------------+
1572+
| | :meth:`str.index`| :meth:`str.rindex` | :meth:`bytes.index`| :meth:`bytes.rindex` |
1573+
| +------------------+------------------------+--------------------+------------------------------+
1574+
| | :meth:`str.startswith` | :meth:`bytes.startswith` |
1575+
| +-------------------------------------------+---------------------------------------------------+
1576+
| | :meth:`str.endswith` | :meth:`bytes.endswith` |
1577+
| +-------------------------------------------+---------------------------------------------------+
1578+
| | :meth:`str.count` | :meth:`bytes.count` |
1579+
| +-------------------------------------------+---------------------------------------------------+
1580+
| | :meth:`str.replace` | :meth:`bytes.replace` |
1581+
+--------------------------+-------------------+-----------------------+---------------------+-----------------------------+
1582+
| Splitting and Joining | :meth:`str.split` | :meth:`str.rsplit` | :meth:`bytes.split` | :meth:`bytes.rsplit` |
1583+
| +-------------------+-----------------------+---------------------+-----------------------------+
1584+
| | :meth:`str.splitlines` | :meth:`bytes.splitlines` |
1585+
| +-------------------------------------------+---------------------------------------------------+
1586+
| | :meth:`str.partition` | :meth:`bytes.partition` |
1587+
| +-------------------------------------------+---------------------------------------------------+
1588+
| | :meth:`str.rpartition` | :meth:`bytes.rpartition` |
1589+
| +-------------------------------------------+---------------------------------------------------+
1590+
| | :meth:`str.join` | :meth:`bytes.join` |
1591+
+--------------------------+-------------------------------------------+---------------------------------------------------+
1592+
| String Classification | :meth:`str.isalpha` | :meth:`bytes.isalpha` |
1593+
| +-------------------------------------------+---------------------------------------------------+
1594+
| | :meth:`str.isdecimal` | |
1595+
| +-------------------------------------------+---------------------------------------------------+
1596+
| | :meth:`str.isdigit` | :meth:`bytes.isdigit` |
1597+
| +-------------------------------------------+---------------------------------------------------+
1598+
| | :meth:`str.isnumeric` | |
1599+
| +-------------------------------------------+---------------------------------------------------+
1600+
| | :meth:`str.isalnum` | :meth:`bytes.isalnum` |
1601+
| +-------------------------------------------+---------------------------------------------------+
1602+
| | :meth:`str.isidentifier` | |
1603+
| +-------------------------------------------+---------------------------------------------------+
1604+
| | :meth:`str.islower` | :meth:`bytes.islower` |
1605+
| +-------------------------------------------+---------------------------------------------------+
1606+
| | :meth:`str.isupper` | :meth:`bytes.isupper` |
1607+
| +-------------------------------------------+---------------------------------------------------+
1608+
| | :meth:`str.istitle` | :meth:`bytes.istitle` |
1609+
| +-------------------------------------------+---------------------------------------------------+
1610+
| | :meth:`str.isspace` | :meth:`bytes.isspace` |
1611+
| +-------------------------------------------+---------------------------------------------------+
1612+
| | :meth:`str.isprintable` | |
1613+
+--------------------------+-------------------------------------------+---------------------------------------------------+
1614+
| Case Manipulation | :meth:`str.lower` | :meth:`bytes.lower` |
1615+
| +-------------------------------------------+---------------------------------------------------+
1616+
| | :meth:`str.upper` | :meth:`bytes.upper` |
1617+
| +-------------------------------------------+---------------------------------------------------+
1618+
| | :meth:`str.casefold` | |
1619+
| +-------------------------------------------+---------------------------------------------------+
1620+
| | :meth:`str.capitalize` | :meth:`bytes.capitalize` |
1621+
| +-------------------------------------------+---------------------------------------------------+
1622+
| | :meth:`str.title` | :meth:`bytes.title` |
1623+
| +-------------------------------------------+---------------------------------------------------+
1624+
| | :meth:`str.swapcase` | :meth:`bytes.swapcase` |
1625+
+--------------------------+-------------------+-----------------------+---------------------+-----------------------------+
1626+
| Padding and Stripping | :meth:`str.ljust` | :meth:`str.rjust` | :meth:`bytes.ljust` | :meth:`bytes.rjust` |
1627+
| +-------------------+-----------------------+---------------------+-----------------------------+
1628+
| | :meth:`str.center` | :meth:`bytes.center` |
1629+
| +-------------------------------------------+---------------------------------------------------+
1630+
| | :meth:`str.expandtabs` | :meth:`bytes.expandtabs` |
1631+
| +-------------------------------------------+---------------------------------------------------+
1632+
| | :meth:`str.strip` | :meth:`bytes.strip` |
1633+
| +--------------------+----------------------+----------------------+----------------------------+
1634+
| | :meth:`str.lstrip` | :meth:`str.rstrip` | :meth:`bytes.lstrip` | :meth:`bytes.rstrip` |
1635+
+--------------------------+--------------------+----------------------+----------------------+----------------------------+
1636+
| Translation and Encoding | :meth:`str.translate` | :meth:`bytes.translate` |
1637+
| +-------------------------------------------+---------------------------------------------------+
1638+
| | :meth:`str.maketrans` | :meth:`bytes.maketrans` |
1639+
| +-------------------------------------------+---------------------------------------------------+
1640+
| | :meth:`str.encode` | |
1641+
| +-------------------------------------------+---------------------------------------------------+
1642+
| | | :meth:`bytes.decode` |
1643+
+--------------------------+-------------------------------------------+---------------------------------------------------+
1644+
15511645
.. _textseq:
15521646

15531647
Text Sequence Type --- :class:`str`

Doc/library/unittest.rst

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,12 @@ Test cases
883883
| :meth:`assertNotIsInstance(a, b) | ``not isinstance(a, b)`` | 3.2 |
884884
| <TestCase.assertNotIsInstance>` | | |
885885
+-----------------------------------------+-----------------------------+---------------+
886+
| :meth:`assertIsSubclass(a, b) | ``issubclass(a, b)`` | 3.14 |
887+
| <TestCase.assertIsSubclass>` | | |
888+
+-----------------------------------------+-----------------------------+---------------+
889+
| :meth:`assertNotIsSubclass(a, b) | ``not issubclass(a, b)`` | 3.14 |
890+
| <TestCase.assertNotIsSubclass>` | | |
891+
+-----------------------------------------+-----------------------------+---------------+
886892

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

963969

970+
.. method:: assertIsSubclass(cls, superclass, msg=None)
971+
assertNotIsSubclass(cls, superclass, msg=None)
972+
973+
Test that *cls* is (or is not) a subclass of *superclass* (which can be a
974+
class or a tuple of classes, as supported by :func:`issubclass`).
975+
To check for the exact type, use :func:`assertIs(cls, superclass) <assertIs>`.
976+
977+
.. versionadded:: next
978+
964979

965980
It is also possible to check the production of exceptions, warnings, and
966981
log messages using the following methods:
@@ -1210,6 +1225,24 @@ Test cases
12101225
| <TestCase.assertCountEqual>` | elements in the same number, | |
12111226
| | regardless of their order. | |
12121227
+---------------------------------------+--------------------------------+--------------+
1228+
| :meth:`assertStartsWith(a, b) | ``a.startswith(b)`` | 3.14 |
1229+
| <TestCase.assertStartsWith>` | | |
1230+
+---------------------------------------+--------------------------------+--------------+
1231+
| :meth:`assertNotStartsWith(a, b) | ``not a.startswith(b)`` | 3.14 |
1232+
| <TestCase.assertNotStartsWith>` | | |
1233+
+---------------------------------------+--------------------------------+--------------+
1234+
| :meth:`assertEndsWith(a, b) | ``a.endswith(b)`` | 3.14 |
1235+
| <TestCase.assertEndsWith>` | | |
1236+
+---------------------------------------+--------------------------------+--------------+
1237+
| :meth:`assertNotEndsWith(a, b) | ``not a.endswith(b)`` | 3.14 |
1238+
| <TestCase.assertNotEndsWith>` | | |
1239+
+---------------------------------------+--------------------------------+--------------+
1240+
| :meth:`assertHasAttr(a, b) | ``hastattr(a, b)`` | 3.14 |
1241+
| <TestCase.assertHasAttr>` | | |
1242+
+---------------------------------------+--------------------------------+--------------+
1243+
| :meth:`assertNotHasAttr(a, b) | ``not hastattr(a, b)`` | 3.14 |
1244+
| <TestCase.assertNotHasAttr>` | | |
1245+
+---------------------------------------+--------------------------------+--------------+
12131246

12141247

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

12811314

1315+
.. method:: assertStartsWith(s, prefix, msg=None)
1316+
.. method:: assertNotStartsWith(s, prefix, msg=None)
1317+
1318+
Test that the Unicode or byte string *s* starts (or does not start)
1319+
with a *prefix*.
1320+
*prefix* can also be a tuple of strings to try.
1321+
1322+
.. versionadded:: next
1323+
1324+
1325+
.. method:: assertEndsWith(s, suffix, msg=None)
1326+
.. method:: assertNotEndsWith(s, suffix, msg=None)
1327+
1328+
Test that the Unicode or byte string *s* ends (or does not end)
1329+
with a *suffix*.
1330+
*suffix* can also be a tuple of strings to try.
1331+
1332+
.. versionadded:: next
1333+
1334+
1335+
.. method:: assertHasAttr(obj, name, msg=None)
1336+
.. method:: assertNotHasAttr(obj, name, msg=None)
1337+
1338+
Test that the object *obj* has (or has not) an attribute *name*.
1339+
1340+
.. versionadded:: next
1341+
1342+
12821343
.. _type-specific-methods:
12831344

12841345
The :meth:`assertEqual` method dispatches the equality check for objects of

0 commit comments

Comments
 (0)