Skip to content

Commit 214f204

Browse files
Merge branch 'main' into range-iter
2 parents 1cd0138 + c9227df commit 214f204

Some content is hidden

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

70 files changed

+864
-192
lines changed

Doc/library/socket.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -808,8 +808,9 @@ The :mod:`socket` module also offers various network-related services:
808808
it is interpreted as the local host. To find the fully qualified name, the
809809
hostname returned by :func:`gethostbyaddr` is checked, followed by aliases for the
810810
host, if available. The first name which includes a period is selected. In
811-
case no fully qualified domain name is available, the hostname as returned by
812-
:func:`gethostname` is returned.
811+
case no fully qualified domain name is available and *name* was provided,
812+
it is returned unchanged. If *name* was empty or equal to ``'0.0.0.0'``,
813+
the hostname from :func:`gethostname` is returned.
813814

814815

815816
.. function:: gethostbyname(hostname)

Doc/library/termios.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,26 @@ The module defines the following functions:
7474
output, :const:`TCIOFF` to suspend input, or :const:`TCION` to restart input.
7575

7676

77+
.. function:: tcgetwinsize(fd)
78+
79+
Return a tuple ``(ws_row, ws_col)`` containing the tty window size for file
80+
descriptor *fd*. Requires :const:`termios.TIOCGWINSZ` or
81+
:const:`termios.TIOCGSIZE`.
82+
83+
.. versionadded:: 3.11
84+
85+
86+
.. function:: tcsetwinsize(fd, winsize)
87+
88+
Set the tty window size for file descriptor *fd* from *winsize*, which is
89+
a two-item tuple ``(ws_row, ws_col)`` like the one returned by
90+
:func:`tcgetwinsize`. Requires at least one of the pairs
91+
(:const:`termios.TIOCGWINSZ`, :const:`termios.TIOCSWINSZ`);
92+
(:const:`termios.TIOCGSIZE`, :const:`termios.TIOCSSIZE`) to be defined.
93+
94+
.. versionadded:: 3.11
95+
96+
7797
.. seealso::
7898

7999
Module :mod:`tty`

Doc/library/unittest.mock.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2020,7 +2020,7 @@ The full list of supported magic methods is:
20202020
* Context manager: ``__enter__``, ``__exit__``, ``__aenter__`` and ``__aexit__``
20212021
* Unary numeric methods: ``__neg__``, ``__pos__`` and ``__invert__``
20222022
* The numeric methods (including right hand and in-place variants):
2023-
``__add__``, ``__sub__``, ``__mul__``, ``__matmul__``, ``__div__``, ``__truediv__``,
2023+
``__add__``, ``__sub__``, ``__mul__``, ``__matmul__``, ``__truediv__``,
20242024
``__floordiv__``, ``__mod__``, ``__divmod__``, ``__lshift__``,
20252025
``__rshift__``, ``__and__``, ``__xor__``, ``__or__``, and ``__pow__``
20262026
* Numeric conversion methods: ``__complex__``, ``__int__``, ``__float__``

Include/internal/pycore_code.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ int _Py_Specialize_StoreAttr(PyObject *owner, _Py_CODEUNIT *instr, PyObject *nam
307307
int _Py_Specialize_LoadGlobal(PyObject *globals, PyObject *builtins, _Py_CODEUNIT *instr, PyObject *name, SpecializedCacheEntry *cache);
308308
int _Py_Specialize_LoadMethod(PyObject *owner, _Py_CODEUNIT *instr, PyObject *name, SpecializedCacheEntry *cache);
309309
int _Py_Specialize_BinarySubscr(PyObject *sub, PyObject *container, _Py_CODEUNIT *instr);
310+
int _Py_Specialize_BinaryAdd(PyObject *sub, PyObject *container, _Py_CODEUNIT *instr);
310311

311312
#define PRINT_SPECIALIZATION_STATS 0
312313
#define PRINT_SPECIALIZATION_STATS_DETAILED 0

Include/internal/pycore_long.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ static inline PyObject* _PyLong_GetZero(void)
3434
static inline PyObject* _PyLong_GetOne(void)
3535
{ return __PyLong_GetSmallInt_internal(1); }
3636

37+
PyObject *_PyLong_Add(PyLongObject *left, PyLongObject *right);
38+
3739
#ifdef __cplusplus
3840
}
3941
#endif

Include/opcode.h

Lines changed: 31 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/_weakrefset.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,14 @@ def _remove(item, selfref=ref(self)):
5151
self.update(data)
5252

5353
def _commit_removals(self):
54-
l = self._pending_removals
54+
pop = self._pending_removals.pop
5555
discard = self.data.discard
56-
while l:
57-
discard(l.pop())
56+
while True:
57+
try:
58+
item = pop()
59+
except IndexError:
60+
return
61+
discard(item)
5862

5963
def __iter__(self):
6064
with _IterationGuard(self):

Lib/opcode.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,11 @@ def jabs_op(name, op):
220220
del def_op, name_op, jrel_op, jabs_op
221221

222222
_specialized_instructions = [
223+
"BINARY_ADD_ADAPTIVE",
224+
"BINARY_ADD_INT",
225+
"BINARY_ADD_FLOAT",
226+
"BINARY_ADD_UNICODE",
227+
"BINARY_ADD_UNICODE_INPLACE_FAST",
223228
"BINARY_SUBSCR_ADAPTIVE",
224229
"BINARY_SUBSCR_LIST_INT",
225230
"BINARY_SUBSCR_TUPLE_INT",

Lib/pydoc.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,13 +1618,14 @@ def pipepager(text, cmd):
16181618
def tempfilepager(text, cmd):
16191619
"""Page through text by invoking a program on a temporary file."""
16201620
import tempfile
1621-
filename = tempfile.mktemp()
1622-
with open(filename, 'w', errors='backslashreplace') as file:
1623-
file.write(text)
1624-
try:
1621+
with tempfile.TemporaryDirectory() as tempdir:
1622+
filename = os.path.join(tempdir, 'pydoc.out')
1623+
with open(filename, 'w', errors='backslashreplace',
1624+
encoding=os.device_encoding(0) if
1625+
sys.platform == 'win32' else None
1626+
) as file:
1627+
file.write(text)
16251628
os.system(cmd + ' "' + filename + '"')
1626-
finally:
1627-
os.unlink(filename)
16281629

16291630
def _escape_stdout(text):
16301631
# Escape non-encodable characters to avoid encoding errors later

Lib/socket.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -782,8 +782,9 @@ def getfqdn(name=''):
782782
An empty argument is interpreted as meaning the local host.
783783
784784
First the hostname returned by gethostbyaddr() is checked, then
785-
possibly existing aliases. In case no FQDN is available, hostname
786-
from gethostname() is returned.
785+
possibly existing aliases. In case no FQDN is available and `name`
786+
was given, it is returned unchanged. If `name` was empty or '0.0.0.0',
787+
hostname from gethostname() is returned.
787788
"""
788789
name = name.strip()
789790
if not name or name == '0.0.0.0':

Lib/sqlite3/test/dbapi.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,9 @@ class MyIter:
476476
def __init__(self):
477477
self.value = 5
478478

479+
def __iter__(self):
480+
return self
481+
479482
def __next__(self):
480483
if self.value == 10:
481484
raise StopIteration

Lib/sqlite3/test/regression.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,11 @@ def test_type_map_usage(self):
126126
con = sqlite.connect(":memory:",detect_types=sqlite.PARSE_DECLTYPES)
127127
con.execute("create table foo(bar timestamp)")
128128
con.execute("insert into foo(bar) values (?)", (datetime.datetime.now(),))
129-
con.execute(SELECT)
129+
con.execute(SELECT).close()
130130
con.execute("drop table foo")
131131
con.execute("create table foo(bar integer)")
132132
con.execute("insert into foo(bar) values (5)")
133-
con.execute(SELECT)
133+
con.execute(SELECT).close()
134134

135135
def test_bind_mutating_list(self):
136136
# Issue41662: Crash when mutate a list of parameters during iteration.

Lib/test/_test_multiprocessing.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,7 @@ def test_lose_target_ref(self):
611611
del c
612612
p.start()
613613
p.join()
614+
gc.collect() # For PyPy or other GCs.
614615
self.assertIs(wr(), None)
615616
self.assertEqual(q.get(), 5)
616617
close_queue(q)
@@ -2667,6 +2668,7 @@ def test_release_task_refs(self):
26672668
self.pool.map(identity, objs)
26682669

26692670
del objs
2671+
gc.collect() # For PyPy or other GCs.
26702672
time.sleep(DELTA) # let threaded cleanup code run
26712673
self.assertEqual(set(wr() for wr in refs), {None})
26722674
# With a process pool, copies of the objects are returned, check
@@ -4198,6 +4200,7 @@ def setUp(self):
41984200
util._finalizer_registry.clear()
41994201

42004202
def tearDown(self):
4203+
gc.collect() # For PyPy or other GCs.
42014204
self.assertFalse(util._finalizer_registry)
42024205
util._finalizer_registry.update(self.registry_backup)
42034206

@@ -4209,12 +4212,14 @@ class Foo(object):
42094212
a = Foo()
42104213
util.Finalize(a, conn.send, args=('a',))
42114214
del a # triggers callback for a
4215+
gc.collect() # For PyPy or other GCs.
42124216

42134217
b = Foo()
42144218
close_b = util.Finalize(b, conn.send, args=('b',))
42154219
close_b() # triggers callback for b
42164220
close_b() # does nothing because callback has already been called
42174221
del b # does nothing because callback has already been called
4222+
gc.collect() # For PyPy or other GCs.
42184223

42194224
c = Foo()
42204225
util.Finalize(c, conn.send, args=('c',))

Lib/test/lock_tests.py

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

55
import os
6+
import gc
67
import sys
78
import time
89
from _thread import start_new_thread, TIMEOUT_MAX
@@ -221,6 +222,7 @@ def test_weakref_deleted(self):
221222
lock = self.locktype()
222223
ref = weakref.ref(lock)
223224
del lock
225+
gc.collect() # For PyPy or other GCs.
224226
self.assertIsNone(ref())
225227

226228

Lib/test/test_array.py

100644100755
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,6 +1097,7 @@ def test_weakref(self):
10971097
p = weakref.proxy(s)
10981098
self.assertEqual(p.tobytes(), s.tobytes())
10991099
s = None
1100+
support.gc_collect() # For PyPy or other GCs.
11001101
self.assertRaises(ReferenceError, len, p)
11011102

11021103
@unittest.skipUnless(hasattr(sys, 'getrefcount'),

Lib/test/test_asyncgen.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import unittest
44

55
from test.support.import_helper import import_module
6+
from test.support import gc_collect
67
asyncio = import_module("asyncio")
78

89

@@ -871,6 +872,7 @@ async def run():
871872
await g.__anext__()
872873
await g.__anext__()
873874
del g
875+
gc_collect() # For PyPy or other GCs.
874876

875877
await asyncio.sleep(0.1)
876878

Lib/test/test_asyncio/test_tasks.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2307,6 +2307,7 @@ async def coro():
23072307
self.new_task(self.loop, gen)
23082308
finally:
23092309
gen.close()
2310+
gc.collect() # For PyPy or other GCs.
23102311

23112312
self.assertTrue(m_log.error.called)
23122313
message = m_log.error.call_args[0][0]

Lib/test/test_code.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@
137137
except ImportError:
138138
ctypes = None
139139
from test.support import (run_doctest, run_unittest, cpython_only,
140-
check_impl_detail, requires_debug_ranges)
140+
check_impl_detail, requires_debug_ranges,
141+
gc_collect)
141142
from test.support.script_helper import assert_python_ok
142143

143144

@@ -510,6 +511,7 @@ def callback(code):
510511
coderef = weakref.ref(f.__code__, callback)
511512
self.assertTrue(bool(coderef()))
512513
del f
514+
gc_collect() # For PyPy or other GCs.
513515
self.assertFalse(bool(coderef()))
514516
self.assertTrue(self.called)
515517

Lib/test/test_concurrent_futures.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ def test_thread_names_assigned(self):
463463
executor.map(abs, range(-5, 5))
464464
threads = executor._threads
465465
del executor
466+
support.gc_collect() # For PyPy or other GCs.
466467

467468
for t in threads:
468469
self.assertRegex(t.name, r'^SpecialPool_[0-4]$')
@@ -473,6 +474,7 @@ def test_thread_names_default(self):
473474
executor.map(abs, range(-5, 5))
474475
threads = executor._threads
475476
del executor
477+
support.gc_collect() # For PyPy or other GCs.
476478

477479
for t in threads:
478480
# Ensure that our default name is reasonably sane and unique when
@@ -535,6 +537,7 @@ def test_del_shutdown(self):
535537
call_queue = executor._call_queue
536538
executor_manager_thread = executor._executor_manager_thread
537539
del executor
540+
support.gc_collect() # For PyPy or other GCs.
538541

539542
# Make sure that all the executor resources were properly cleaned by
540543
# the shutdown process
@@ -759,13 +762,15 @@ def test_free_reference_yielded_future(self):
759762
futures_list.remove(future)
760763
wr = weakref.ref(future)
761764
del future
765+
support.gc_collect() # For PyPy or other GCs.
762766
self.assertIsNone(wr())
763767

764768
futures_list[0].set_result("test")
765769
for future in futures.as_completed(futures_list):
766770
futures_list.remove(future)
767771
wr = weakref.ref(future)
768772
del future
773+
support.gc_collect() # For PyPy or other GCs.
769774
self.assertIsNone(wr())
770775
if futures_list:
771776
futures_list[0].set_result("test")
@@ -865,6 +870,7 @@ def test_free_reference(self):
865870
for obj in self.executor.map(make_dummy_object, range(10)):
866871
wr = weakref.ref(obj)
867872
del obj
873+
support.gc_collect() # For PyPy or other GCs.
868874
self.assertIsNone(wr())
869875

870876

0 commit comments

Comments
 (0)