Skip to content

Commit 6067904

Browse files
authored
Merge branch 'main' into fix-issue-119247
2 parents 3e580d6 + b7f45a9 commit 6067904

36 files changed

+1633
-1563
lines changed

Doc/c-api/hash.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ See also the :c:member:`PyTypeObject.tp_hash` member and :ref:`numeric-hash`.
2929

3030
.. versionadded:: 3.13
3131

32+
.. c:macro:: PyHASH_MULTIPLIER
33+
34+
Prime multiplier used in string and various other hashes.
35+
36+
.. versionadded:: 3.13
37+
3238
.. c:macro:: PyHASH_INF
3339
3440
The hash value returned for a positive infinity.

Doc/library/socket.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1589,7 +1589,8 @@ to sockets.
15891589
Return a :term:`file object` associated with the socket. The exact returned
15901590
type depends on the arguments given to :meth:`makefile`. These arguments are
15911591
interpreted the same way as by the built-in :func:`open` function, except
1592-
the only supported *mode* values are ``'r'`` (default), ``'w'`` and ``'b'``.
1592+
the only supported *mode* values are ``'r'`` (default), ``'w'``, ``'b'``, or
1593+
a combination of those.
15931594

15941595
The socket must be in blocking mode; it can have a timeout, but the file
15951596
object's internal buffer may end up in an inconsistent state if a timeout

Doc/tutorial/inputoutput.rst

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,23 @@ printing space-separated values. There are several ways to format output.
3737
* The :meth:`str.format` method of strings requires more manual
3838
effort. You'll still use ``{`` and ``}`` to mark where a variable
3939
will be substituted and can provide detailed formatting directives,
40-
but you'll also need to provide the information to be formatted.
40+
but you'll also need to provide the information to be formatted. In the following code
41+
block there are two examples of how to format variables:
42+
4143

4244
::
4345

4446
>>> yes_votes = 42_572_654
45-
>>> no_votes = 43_132_495
46-
>>> percentage = yes_votes / (yes_votes + no_votes)
47+
>>> total_votes = 85_705_149
48+
>>> percentage = yes_votes / total_votes
4749
>>> '{:-9} YES votes {:2.2%}'.format(yes_votes, percentage)
4850
' 42572654 YES votes 49.67%'
4951

52+
Notice how the ``yes_votes`` are padded with spaces and a negative sign only for negative numbers.
53+
The example also prints ``percentage`` multiplied by 100, with 2 decimal
54+
places and followed by a percent sign (see :ref:`formatspec` for details).
55+
56+
5057
* Finally, you can do all the string handling yourself by using string slicing and
5158
concatenation operations to create any layout you can imagine. The
5259
string type has some methods that perform useful operations for padding
@@ -197,7 +204,12 @@ notation. ::
197204
Jack: 4098; Sjoerd: 4127; Dcab: 8637678
198205

199206
This is particularly useful in combination with the built-in function
200-
:func:`vars`, which returns a dictionary containing all local variables.
207+
:func:`vars`, which returns a dictionary containing all local variables::
208+
209+
>>> table = {k: str(v) for k, v in vars().items()}
210+
>>> message = " ".join([f'{k}: ' + '{' + k +'};' for k in table.keys()])
211+
>>> print(message.format(**table))
212+
__name__: __main__; __doc__: None; __package__: None; __loader__: ...
201213

202214
As an example, the following lines produce a tidily aligned
203215
set of columns giving integers and their squares and cubes::

Include/cpython/pyhash.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#endif
44

55
/* Prime multiplier used in string and various other hashes. */
6-
#define _PyHASH_MULTIPLIER 1000003UL /* 0xf4243 */
6+
#define PyHASH_MULTIPLIER 1000003UL /* 0xf4243 */
77

88
/* Parameters used for the numeric hash implementation. See notes for
99
_Py_HashDouble in Python/pyhash.c. Numeric hashes are based on
@@ -17,9 +17,10 @@
1717

1818
#define PyHASH_MODULUS (((size_t)1 << _PyHASH_BITS) - 1)
1919
#define PyHASH_INF 314159
20-
#define PyHASH_IMAG _PyHASH_MULTIPLIER
20+
#define PyHASH_IMAG PyHASH_MULTIPLIER
2121

2222
/* Aliases kept for backward compatibility with Python 3.12 */
23+
#define _PyHASH_MULTIPLIER PyHASH_MULTIPLIER
2324
#define _PyHASH_BITS PyHASH_BITS
2425
#define _PyHASH_MODULUS PyHASH_MODULUS
2526
#define _PyHASH_INF PyHASH_INF

Lib/_pyrepl/keymap.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,12 @@ def _parse_key1(key, s):
177177
ret = key[s]
178178
s += 1
179179
if ctrl:
180-
if len(ret) > 1:
181-
raise KeySpecError("\\C- must be followed by a character")
182-
ret = chr(ord(ret) & 0x1F) # curses.ascii.ctrl()
180+
if len(ret) == 1:
181+
ret = chr(ord(ret) & 0x1F) # curses.ascii.ctrl()
182+
elif ret in {"left", "right"}:
183+
ret = f"ctrl {ret}"
184+
else:
185+
raise KeySpecError("\\C- followed by invalid key")
183186
if meta:
184187
ret = ["\033", ret]
185188
else:

Lib/_pyrepl/reader.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ def make_default_commands() -> dict[CommandName, type[Command]]:
136136
(r"\<up>", "up"),
137137
(r"\<down>", "down"),
138138
(r"\<left>", "left"),
139+
(r"\C-\<left>", "backward-word"),
139140
(r"\<right>", "right"),
141+
(r"\C-\<right>", "forward-word"),
140142
(r"\<delete>", "delete"),
141143
(r"\<backspace>", "backspace"),
142144
(r"\M-\<backspace>", "backward-kill-word"),

Lib/rlcompleter.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import keyword
3636
import re
3737
import __main__
38+
import warnings
3839

3940
__all__ = ["Completer"]
4041

@@ -88,10 +89,11 @@ def complete(self, text, state):
8889
return None
8990

9091
if state == 0:
91-
if "." in text:
92-
self.matches = self.attr_matches(text)
93-
else:
94-
self.matches = self.global_matches(text)
92+
with warnings.catch_warnings(action="ignore"):
93+
if "." in text:
94+
self.matches = self.attr_matches(text)
95+
else:
96+
self.matches = self.global_matches(text)
9597
try:
9698
return self.matches[state]
9799
except IndexError:

Lib/socket.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,8 @@ def makefile(self, mode="r", buffering=None, *,
306306
"""makefile(...) -> an I/O stream connected to the socket
307307
308308
The arguments are as for io.open() after the filename, except the only
309-
supported mode values are 'r' (default), 'w' and 'b'.
309+
supported mode values are 'r' (default), 'w', 'b', or a combination of
310+
those.
310311
"""
311312
# XXX refactor to share code?
312313
if not set(mode) <= {"r", "w", "b"}:

Lib/test/test_itertools.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ def test_count(self):
546546
#check proper internal error handling for large "step' sizes
547547
count(1, maxsize+5); sys.exc_info()
548548

549-
def test_count_with_stride(self):
549+
def test_count_with_step(self):
550550
self.assertEqual(lzip('abc',count(2,3)), [('a', 2), ('b', 5), ('c', 8)])
551551
self.assertEqual(lzip('abc',count(start=2,step=3)),
552552
[('a', 2), ('b', 5), ('c', 8)])
@@ -590,6 +590,28 @@ def test_count_with_stride(self):
590590
self.assertEqual(type(next(c)), int)
591591
self.assertEqual(type(next(c)), float)
592592

593+
@threading_helper.requires_working_threading()
594+
def test_count_threading(self, step=1):
595+
# this test verifies multithreading consistency, which is
596+
# mostly for testing builds without GIL, but nice to test anyway
597+
count_to = 10_000
598+
num_threads = 10
599+
c = count(step=step)
600+
def counting_thread():
601+
for i in range(count_to):
602+
next(c)
603+
threads = []
604+
for i in range(num_threads):
605+
thread = threading.Thread(target=counting_thread)
606+
thread.start()
607+
threads.append(thread)
608+
for thread in threads:
609+
thread.join()
610+
self.assertEqual(next(c), count_to * num_threads * step)
611+
612+
def test_count_with_step_threading(self):
613+
self.test_count_threading(step=5)
614+
593615
def test_cycle(self):
594616
self.assertEqual(take(10, cycle('abc')), list('abcabcabca'))
595617
self.assertEqual(list(cycle('')), [])

0 commit comments

Comments
 (0)