Skip to content

Commit 36adb8a

Browse files
authored
Merge branch 'main' into pythongh-90812
2 parents d86cbc6 + e94d168 commit 36adb8a

Some content is hidden

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

59 files changed

+496
-363
lines changed

Doc/c-api/unicode.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,14 @@ APIs:
596596
Objects other than Unicode or its subtypes will cause a :exc:`TypeError`.
597597
598598
599+
.. c:function:: PyObject* PyUnicode_FromOrdinal(int ordinal)
600+
601+
Create a Unicode Object from the given Unicode code point *ordinal*.
602+
603+
The ordinal must be in ``range(0x110000)``. A :exc:`ValueError` is
604+
raised in the case it is not.
605+
606+
599607
.. c:function:: PyObject* PyUnicode_FromEncodedObject(PyObject *obj, \
600608
const char *encoding, const char *errors)
601609

Doc/data/refcounts.dat

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2770,6 +2770,9 @@ PyUnicode_FromFormatV:PyObject*::+1:
27702770
PyUnicode_FromFormatV:const char*:format::
27712771
PyUnicode_FromFormatV:va_list:args::
27722772

2773+
PyUnicode_FromOrdinal:PyObject*::+1:
2774+
PyUnicode_FromOrdinal:int:ordinal::
2775+
27732776
PyUnicode_Append:void:::
27742777
PyUnicode_Append:PyObject**:p_left:0:
27752778
PyUnicode_Append:PyObject*:right::

Doc/library/codecs.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ any codec:
5555

5656
The full details for each codec can also be looked up directly:
5757

58-
.. function:: lookup(encoding)
58+
.. function:: lookup(encoding, /)
5959

6060
Looks up the codec info in the Python codec registry and returns a
6161
:class:`CodecInfo` object as defined below.
@@ -156,7 +156,7 @@ these additional functions which use :func:`lookup` for the codec lookup:
156156
Custom codecs are made available by registering a suitable codec search
157157
function:
158158

159-
.. function:: register(search_function)
159+
.. function:: register(search_function, /)
160160

161161
Register a codec search function. Search functions are expected to take one
162162
argument, being the encoding name in all lower case letters with hyphens
@@ -168,7 +168,7 @@ function:
168168
Hyphens and spaces are converted to underscore.
169169

170170

171-
.. function:: unregister(search_function)
171+
.. function:: unregister(search_function, /)
172172

173173
Unregister a codec search function and clear the registry's cache.
174174
If the search function is not registered, do nothing.
@@ -416,7 +416,7 @@ In addition, the following error handler is specific to the given codecs:
416416
The set of allowed values can be extended by registering a new named error
417417
handler:
418418

419-
.. function:: register_error(name, error_handler)
419+
.. function:: register_error(name, error_handler, /)
420420

421421
Register the error handling function *error_handler* under the name *name*.
422422
The *error_handler* argument will be called during encoding and decoding
@@ -442,7 +442,7 @@ handler:
442442
Previously registered error handlers (including the standard error handlers)
443443
can be looked up by name:
444444

445-
.. function:: lookup_error(name)
445+
.. function:: lookup_error(name, /)
446446

447447
Return the error handler previously registered under the name *name*.
448448

Doc/library/signal.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -510,10 +510,12 @@ The :mod:`signal` module defines the following functions:
510510

511511
.. function:: set_wakeup_fd(fd, *, warn_on_full_buffer=True)
512512

513-
Set the wakeup file descriptor to *fd*. When a signal is received, the
514-
signal number is written as a single byte into the fd. This can be used by
515-
a library to wakeup a poll or select call, allowing the signal to be fully
516-
processed.
513+
Set the wakeup file descriptor to *fd*. When a signal your program has
514+
registered a signal handler for is received, the signal number is written as
515+
a single byte into the fd. If you haven't registered a signal handler for
516+
the signals you care about, then nothing will be written to the wakeup fd.
517+
This can be used by a library to wakeup a poll or select call, allowing the
518+
signal to be fully processed.
517519

518520
The old wakeup fd is returned (or -1 if file descriptor wakeup was not
519521
enabled). If *fd* is -1, file descriptor wakeup is disabled.

Doc/library/socket.rst

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -156,21 +156,25 @@ created. Socket addresses are represented as follows:
156156

157157
- :const:`BTPROTO_HCI` accepts a format that depends on your OS.
158158

159-
- On Linux it accepts a tuple ``(device_id,)`` where ``device_id``
160-
is an integer specifying the number of the Bluetooth device.
161-
- On FreeBSD, NetBSD and DragonFly BSD it accepts ``bdaddr`` where ``bdaddr``
162-
is a :class:`bytes` object containing the Bluetooth address in a
163-
string format. (ex. ``b'12:23:34:45:56:67'``)
159+
- On Linux it accepts a tuple ``(device_id, [channel])`` where ``device_id``
160+
is an integer specifying the number of the Bluetooth device,
161+
and ``channel`` is an optional integer specifying the HCI channel
162+
(:const:`HCI_CHANNEL_RAW` by default).
163+
- On FreeBSD, NetBSD and DragonFly BSD it accepts ``bdaddr``
164+
where ``bdaddr`` is the Bluetooth address as a string.
164165

165166
.. versionchanged:: 3.2
166167
NetBSD and DragonFlyBSD support added.
167168

168169
.. versionchanged:: 3.13.3
169170
FreeBSD support added.
170171

171-
- :const:`BTPROTO_SCO` accepts ``bdaddr`` where ``bdaddr`` is a
172-
:class:`bytes` object containing the Bluetooth address in a
173-
string format. (ex. ``b'12:23:34:45:56:67'``)
172+
.. versionchanged:: next
173+
Added ``channel`` field.
174+
175+
- :const:`BTPROTO_SCO` accepts ``bdaddr`` where ``bdaddr`` is
176+
the Bluetooth address as a string or a :class:`bytes` object.
177+
(ex. ``'12:23:34:45:56:67'`` or ``b'12:23:34:45:56:67'``)
174178

175179
.. versionchanged:: next
176180
FreeBSD support added.
@@ -678,6 +682,18 @@ Constants
678682
available on Linux and FreeBSD. :const:`!HCI_TIME_STAMP` and
679683
:const:`!HCI_DATA_DIR` are only available on Linux.
680684

685+
.. data:: HCI_CHANNEL_RAW
686+
HCI_CHANNEL_USER
687+
HCI_CHANNEL_MONITOR
688+
HCI_CHANNEL_CONTROL
689+
HCI_CHANNEL_LOGGING
690+
691+
Possible values for ``channel`` field in the :const:`BTPROTO_HCI` address.
692+
693+
.. availability:: Linux
694+
695+
.. versionadded:: next
696+
681697
.. data:: AF_QIPCRTR
682698

683699
Constant for Qualcomm's IPC router protocol, used to communicate with

Doc/library/sys.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ always available. Unless explicitly noted otherwise, all variables are read-only
130130

131131
.. data:: base_exec_prefix
132132

133-
Equivalent to :data:`exec_prefix`, but refering to the base Python installation.
133+
Equivalent to :data:`exec_prefix`, but referring to the base Python installation.
134134

135135
When running under :ref:`sys-path-init-virtual-environments`,
136136
:data:`exec_prefix` gets overwritten to the virtual environment prefix.
@@ -143,7 +143,7 @@ always available. Unless explicitly noted otherwise, all variables are read-only
143143

144144
.. data:: base_prefix
145145

146-
Equivalent to :data:`prefix`, but refering to the base Python installation.
146+
Equivalent to :data:`prefix`, but referring to the base Python installation.
147147

148148
When running under :ref:`virtual environment <venv-def>`,
149149
:data:`prefix` gets overwritten to the virtual environment prefix.

Doc/library/sys_path_init.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ Please refer to :mod:`site`'s
9797
.. note::
9898

9999
There are other ways how "virtual environments" could be implemented, this
100-
documentation referes implementations based on the ``pyvenv.cfg`` mechanism,
100+
documentation refers implementations based on the ``pyvenv.cfg`` mechanism,
101101
such as :mod:`venv`. Most virtual environment implementations follow the
102102
model set by :mod:`venv`, but there may be exotic implementations that
103103
diverge from it.

Doc/library/test.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,7 @@ The :mod:`test.support` module defines the following functions:
853853

854854
.. function:: linked_with_musl()
855855

856-
Return ``False`` if there is no evidence the interperter was compiled with
856+
Return ``False`` if there is no evidence the interpreter was compiled with
857857
``musl``, otherwise return a version triple, either ``(0, 0, 0)`` if the
858858
version is unknown, or the actual version if it is known. Intended for use
859859
in ``skip`` decorators. ``emscripten`` and ``wasi`` are assumed to be

Doc/library/urllib.request.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,9 @@ The :mod:`urllib.request` module defines the following functions:
199199

200200
.. versionchanged:: next
201201
This function calls :func:`socket.gethostbyname` if the URL authority
202-
isn't empty or ``localhost``. If the authority resolves to a local IP
203-
address then it is discarded; otherwise, on Windows a UNC path is
204-
returned (as before), and on other platforms a
202+
isn't empty, ``localhost``, or the machine hostname. If the authority
203+
resolves to a local IP address then it is discarded; otherwise, on
204+
Windows a UNC path is returned (as before), and on other platforms a
205205
:exc:`~urllib.error.URLError` is raised.
206206

207207
.. versionchanged:: next

Include/internal/pycore_pyatomic_ft_wrappers.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ extern "C" {
109109
_Py_atomic_store_ullong_relaxed(&value, new_value)
110110
#define FT_ATOMIC_LOAD_ULLONG_RELAXED(value) \
111111
_Py_atomic_load_ullong_relaxed(&value)
112+
#define FT_ATOMIC_ADD_SSIZE(value, new_value) \
113+
(void)_Py_atomic_add_ssize(&value, new_value)
112114

113115
#else
114116
#define FT_ATOMIC_LOAD_PTR(value) value
@@ -156,6 +158,7 @@ extern "C" {
156158
#define FT_ATOMIC_STORE_LLONG_RELAXED(value, new_value) value = new_value
157159
#define FT_ATOMIC_LOAD_ULLONG_RELAXED(value) value
158160
#define FT_ATOMIC_STORE_ULLONG_RELAXED(value, new_value) value = new_value
161+
#define FT_ATOMIC_ADD_SSIZE(value, new_value) (void)(value += new_value)
159162

160163
#endif
161164

Include/internal/pycore_uop_metadata.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/_pydecimal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6098,7 +6098,7 @@ def _convert_for_comparison(self, other, equality_op=False):
60986098
(?P<alt>\#)?
60996099
(?P<zeropad>0)?
61006100
(?P<minimumwidth>(?!0)\d+)?
6101-
(?P<thousands_sep>,)?
6101+
(?P<thousands_sep>[,_])?
61026102
(?:\.(?P<precision>0|(?!0)\d+))?
61036103
(?P<type>[eEfFgGn%])?
61046104
\Z

Lib/test/audit-tests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,10 +311,10 @@ def test_ctypes_call_function():
311311

312312
with TestHook() as hook:
313313
_ctypes.call_function(ctypes._memmove_addr, (0, 0, 0))
314-
assert ("ctypes.call_function", (ctypes._memmove_addr, (0, 0, 0))) in hook.seen
314+
assert ("ctypes.call_function", (ctypes._memmove_addr, (0, 0, 0))) in hook.seen, f"{ctypes._memmove_addr=} {hook.seen=}"
315315

316316
ctypes.CFUNCTYPE(ctypes.c_voidp)(ctypes._memset_addr)(1, 0, 0)
317-
assert ("ctypes.call_function", (ctypes._memset_addr, (1, 0, 0))) in hook.seen
317+
assert ("ctypes.call_function", (ctypes._memset_addr, (1, 0, 0))) in hook.seen, f"{ctypes._memset_addr=} {hook.seen=}"
318318

319319
with TestHook() as hook:
320320
ctypes.cast(ctypes.c_voidp(0), ctypes.POINTER(ctypes.c_char))

Lib/test/test_dataclasses/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3635,7 +3635,6 @@ class A(Base):
36353635
a_ref = weakref.ref(a)
36363636
self.assertIs(a.__weakref__, a_ref)
36373637

3638-
36393638
def test_dataclass_derived_weakref_slot(self):
36403639
class A:
36413640
pass
@@ -3715,7 +3714,7 @@ class F[T2](WithSlots):
37153714
self.assertTrue(F.__weakref__)
37163715
F()
37173716

3718-
def test_dataclass_derived_generic_from_slotted_base(self):
3717+
def test_dataclass_derived_generic_from_slotted_base_with_weakref(self):
37193718
T = typing.TypeVar('T')
37203719

37213720
class WithWeakrefSlot:

Lib/test/test_decimal.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,11 @@ def test_formatting(self):
10831083
(',%', '123.456789', '12,345.6789%'),
10841084
(',e', '123456', '1.23456e+5'),
10851085
(',E', '123456', '1.23456E+5'),
1086+
# ... with '_' instead
1087+
('_', '1234567', '1_234_567'),
1088+
('07_', '1234.56', '1_234.56'),
1089+
('_', '1.23456789', '1.23456789'),
1090+
('_%', '123.456789', '12_345.6789%'),
10861091

10871092
# negative zero: default behavior
10881093
('.1f', '-0', '-0.0'),

Lib/test/test_email/test_contentmanager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ def test_get_message_non_rfc822_or_external_body_yields_bytes(self):
288288
289289
The real body is in another message.
290290
"""))
291-
self.assertEqual(raw_data_manager.get_content(m)[:10], b'To: foo@ex')
291+
self.assertStartsWith(raw_data_manager.get_content(m), b'To: foo@ex')
292292

293293
def test_set_text_plain(self):
294294
m = self._make_message()

Lib/test/test_email/test_defect_handling.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def test_same_boundary_inner_outer(self):
5757
msg = self._str_msg(source)
5858
if self.raise_expected: return
5959
inner = msg.get_payload(0)
60-
self.assertTrue(hasattr(inner, 'defects'))
60+
self.assertHasAttr(inner, 'defects')
6161
self.assertEqual(len(self.get_defects(inner)), 1)
6262
self.assertIsInstance(self.get_defects(inner)[0],
6363
errors.StartBoundaryNotFoundDefect)
@@ -151,7 +151,7 @@ def test_lying_multipart(self):
151151
with self._raise_point(errors.NoBoundaryInMultipartDefect):
152152
msg = self._str_msg(source)
153153
if self.raise_expected: return
154-
self.assertTrue(hasattr(msg, 'defects'))
154+
self.assertHasAttr(msg, 'defects')
155155
self.assertEqual(len(self.get_defects(msg)), 2)
156156
self.assertIsInstance(self.get_defects(msg)[0],
157157
errors.NoBoundaryInMultipartDefect)

Lib/test/test_email/test_email.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,8 @@ def test_make_boundary(self):
210210
self.assertEqual(msg.items()[0][1], 'multipart/form-data')
211211
# Trigger creation of boundary
212212
msg.as_string()
213-
self.assertEqual(msg.items()[0][1][:33],
214-
'multipart/form-data; boundary="==')
213+
self.assertStartsWith(msg.items()[0][1],
214+
'multipart/form-data; boundary="==')
215215
# XXX: there ought to be tests of the uniqueness of the boundary, too.
216216

217217
def test_message_rfc822_only(self):
@@ -303,7 +303,7 @@ def test_as_string(self):
303303
self.assertEqual(text, str(msg))
304304
fullrepr = msg.as_string(unixfrom=True)
305305
lines = fullrepr.split('\n')
306-
self.assertTrue(lines[0].startswith('From '))
306+
self.assertStartsWith(lines[0], 'From ')
307307
self.assertEqual(text, NL.join(lines[1:]))
308308

309309
def test_as_string_policy(self):
@@ -372,7 +372,7 @@ def test_as_bytes(self):
372372
self.assertEqual(data, bytes(msg))
373373
fullrepr = msg.as_bytes(unixfrom=True)
374374
lines = fullrepr.split(b'\n')
375-
self.assertTrue(lines[0].startswith(b'From '))
375+
self.assertStartsWith(lines[0], b'From ')
376376
self.assertEqual(data, b'\n'.join(lines[1:]))
377377

378378
def test_as_bytes_policy(self):
@@ -2228,7 +2228,7 @@ def test_same_boundary_inner_outer(self):
22282228
msg = self._msgobj('msg_15.txt')
22292229
# XXX We can probably eventually do better
22302230
inner = msg.get_payload(0)
2231-
self.assertTrue(hasattr(inner, 'defects'))
2231+
self.assertHasAttr(inner, 'defects')
22322232
self.assertEqual(len(inner.defects), 1)
22332233
self.assertIsInstance(inner.defects[0],
22342234
errors.StartBoundaryNotFoundDefect)
@@ -2340,7 +2340,7 @@ def test_no_separating_blank_line(self):
23402340
# test_defect_handling
23412341
def test_lying_multipart(self):
23422342
msg = self._msgobj('msg_41.txt')
2343-
self.assertTrue(hasattr(msg, 'defects'))
2343+
self.assertHasAttr(msg, 'defects')
23442344
self.assertEqual(len(msg.defects), 2)
23452345
self.assertIsInstance(msg.defects[0],
23462346
errors.NoBoundaryInMultipartDefect)
@@ -3684,9 +3684,7 @@ def test_make_msgid_idstring(self):
36843684
def test_make_msgid_default_domain(self):
36853685
with patch('socket.getfqdn') as mock_getfqdn:
36863686
mock_getfqdn.return_value = domain = 'pythontest.example.com'
3687-
self.assertTrue(
3688-
email.utils.make_msgid().endswith(
3689-
'@' + domain + '>'))
3687+
self.assertEndsWith(email.utils.make_msgid(), '@' + domain + '>')
36903688

36913689
def test_Generator_linend(self):
36923690
# Issue 14645.
@@ -4153,7 +4151,7 @@ def test_CRLFLF_at_end_of_part(self):
41534151
"--BOUNDARY--\n"
41544152
)
41554153
msg = email.message_from_string(m)
4156-
self.assertTrue(msg.get_payload(0).get_payload().endswith('\r\n'))
4154+
self.assertEndsWith(msg.get_payload(0).get_payload(), '\r\n')
41574155

41584156

41594157
class Test8BitBytesHandling(TestEmailBase):

Lib/test/test_generated_cases.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1862,13 +1862,28 @@ def test_multiple_labels(self):
18621862

18631863
def test_reassigning_live_inputs(self):
18641864
input = """
1865-
inst(OP, (in -- )) {
1865+
inst(OP, (in -- in)) {
18661866
in = 0;
1867-
DEAD(in);
18681867
}
18691868
"""
1870-
with self.assertRaises(SyntaxError):
1871-
self.run_cases_test(input, "")
1869+
1870+
output = """
1871+
TARGET(OP) {
1872+
#if Py_TAIL_CALL_INTERP
1873+
int opcode = OP;
1874+
(void)(opcode);
1875+
#endif
1876+
frame->instr_ptr = next_instr;
1877+
next_instr += 1;
1878+
INSTRUCTION_STATS(OP);
1879+
_PyStackRef in;
1880+
in = stack_pointer[-1];
1881+
in = 0;
1882+
stack_pointer[-1] = in;
1883+
DISPATCH();
1884+
}
1885+
"""
1886+
self.run_cases_test(input, output)
18721887

18731888
def test_reassigning_dead_inputs(self):
18741889
input = """

0 commit comments

Comments
 (0)