Skip to content

Commit 7d5f63e

Browse files
authored
Merge branch 'main' into __annotations__-on-instances-is-not-supported-behavior
2 parents 91144a4 + 1298511 commit 7d5f63e

26 files changed

+493
-155
lines changed

Doc/library/curses.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,10 @@ the following methods and attributes:
988988
window.getstr(y, x, n)
989989

990990
Read a bytes object from the user, with primitive line editing capacity.
991+
The maximum value for *n* is 2047.
992+
993+
.. versionchanged:: 3.14
994+
The maximum value for *n* was increased from 1023 to 2047.
991995

992996

993997
.. method:: window.getyx()
@@ -1079,6 +1083,10 @@ the following methods and attributes:
10791083
current cursor position, or at *y*, *x* if specified. Attributes are stripped
10801084
from the characters. If *n* is specified, :meth:`instr` returns a string
10811085
at most *n* characters long (exclusive of the trailing NUL).
1086+
The maximum value for *n* is 2047.
1087+
1088+
.. versionchanged:: 3.14
1089+
The maximum value for *n* was increased from 1023 to 2047.
10821090

10831091

10841092
.. method:: window.is_linetouched(line)

Doc/library/pdb.rst

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ The debugger's prompt is ``(Pdb)``, which is the indicator that you are in debug
8080
You can also invoke :mod:`pdb` from the command line to debug other scripts. For
8181
example::
8282

83-
python -m pdb [-c command] (-m module | pyfile) [args ...]
83+
python -m pdb [-c command] (-m module | -p pid | pyfile) [args ...]
8484

8585
When invoked as a module, pdb will automatically enter post-mortem debugging if
8686
the program being debugged exits abnormally. After post-mortem debugging (or
@@ -104,6 +104,24 @@ useful than quitting the debugger upon program's exit.
104104
.. versionchanged:: 3.7
105105
Added the ``-m`` option.
106106

107+
.. option:: -p, --pid <pid>
108+
109+
Attach to the process with the specified PID.
110+
111+
.. versionadded:: 3.14
112+
113+
114+
To attach to a running Python process for remote debugging, use the ``-p`` or
115+
``--pid`` option with the target process's PID::
116+
117+
python -m pdb -p 1234
118+
119+
.. note::
120+
121+
Attaching to a process that is blocked in a system call or waiting for I/O
122+
will only work once the next bytecode instruction is executed or when the
123+
process receives a signal.
124+
107125
Typical usage to execute a statement under control of the debugger is::
108126

109127
>>> import pdb

Include/internal/pycore_uop_ids.h

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

Include/internal/pycore_uop_metadata.h

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

Lib/_pyrepl/_module_completer.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,10 @@ def find_modules(self, path: str, prefix: str) -> list[str]:
8181
def _find_modules(self, path: str, prefix: str) -> list[str]:
8282
if not path:
8383
# Top-level import (e.g. `import foo<tab>`` or `from foo<tab>`)`
84-
builtin_modules = [name for name in sys.builtin_module_names if name.startswith(prefix)]
85-
third_party_modules = [name for _, name, _ in self.global_cache if name.startswith(prefix)]
84+
builtin_modules = [name for name in sys.builtin_module_names
85+
if self.is_suggestion_match(name, prefix)]
86+
third_party_modules = [module.name for module in self.global_cache
87+
if self.is_suggestion_match(module.name, prefix)]
8688
return sorted(builtin_modules + third_party_modules)
8789

8890
if path.startswith('.'):
@@ -98,7 +100,14 @@ def _find_modules(self, path: str, prefix: str) -> list[str]:
98100
if mod_info.ispkg and mod_info.name == segment]
99101
modules = self.iter_submodules(modules)
100102
return [module.name for module in modules
101-
if module.name.startswith(prefix)]
103+
if self.is_suggestion_match(module.name, prefix)]
104+
105+
def is_suggestion_match(self, module_name: str, prefix: str) -> bool:
106+
if prefix:
107+
return module_name.startswith(prefix)
108+
# For consistency with attribute completion, which
109+
# does not suggest private attributes unless requested.
110+
return not module_name.startswith("_")
102111

103112
def iter_submodules(self, parent_modules: list[pkgutil.ModuleInfo]) -> Iterator[pkgutil.ModuleInfo]:
104113
"""Iterate over all submodules of the given parent modules."""

Lib/pdb.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3489,7 +3489,8 @@ def help():
34893489
_usage = """\
34903490
Debug the Python program given by pyfile. Alternatively,
34913491
an executable module or package to debug can be specified using
3492-
the -m switch.
3492+
the -m switch. You can also attach to a running Python process
3493+
using the -p option with its PID.
34933494
34943495
Initial commands are read from .pdbrc files in your home directory
34953496
and in the current directory, if they exist. Commands supplied with

Lib/test/test_capi/test_opt.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1925,6 +1925,50 @@ def testfunc(n):
19251925
self.assertNotIn("_GUARD_NOS_INT", uops)
19261926
self.assertNotIn("_GUARD_TOS_INT", uops)
19271927

1928+
def test_get_len_with_const_tuple(self):
1929+
def testfunc(n):
1930+
x = 0.0
1931+
for _ in range(n):
1932+
match (1, 2, 3, 4):
1933+
case [_, _, _, _]:
1934+
x += 1.0
1935+
return x
1936+
res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
1937+
self.assertEqual(int(res), TIER2_THRESHOLD)
1938+
uops = get_opnames(ex)
1939+
self.assertNotIn("_GUARD_NOS_INT", uops)
1940+
self.assertNotIn("_GET_LEN", uops)
1941+
self.assertIn("_LOAD_CONST_INLINE_BORROW", uops)
1942+
1943+
def test_get_len_with_non_const_tuple(self):
1944+
def testfunc(n):
1945+
x = 0.0
1946+
for _ in range(n):
1947+
match object(), object():
1948+
case [_, _]:
1949+
x += 1.0
1950+
return x
1951+
res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
1952+
self.assertEqual(int(res), TIER2_THRESHOLD)
1953+
uops = get_opnames(ex)
1954+
self.assertNotIn("_GUARD_NOS_INT", uops)
1955+
self.assertNotIn("_GET_LEN", uops)
1956+
self.assertIn("_LOAD_CONST_INLINE_BORROW", uops)
1957+
1958+
def test_get_len_with_non_tuple(self):
1959+
def testfunc(n):
1960+
x = 0.0
1961+
for _ in range(n):
1962+
match [1, 2, 3, 4]:
1963+
case [_, _, _, _]:
1964+
x += 1.0
1965+
return x
1966+
res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
1967+
self.assertEqual(int(res), TIER2_THRESHOLD)
1968+
uops = get_opnames(ex)
1969+
self.assertNotIn("_GUARD_NOS_INT", uops)
1970+
self.assertIn("_GET_LEN", uops)
1971+
19281972
def test_binary_op_subscr_tuple_int(self):
19291973
def testfunc(n):
19301974
x = 0
@@ -2093,6 +2137,25 @@ def testfunc(n):
20932137
self.assertNotIn("_TO_BOOL_BOOL", uops)
20942138
self.assertIn("_GUARD_IS_TRUE_POP", uops)
20952139

2140+
def test_set_type_version_sets_type(self):
2141+
class C:
2142+
A = 1
2143+
2144+
def testfunc(n):
2145+
x = 0
2146+
c = C()
2147+
for _ in range(n):
2148+
x += c.A # Guarded.
2149+
x += type(c).A # Unguarded!
2150+
return x
2151+
2152+
res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
2153+
self.assertEqual(res, 2 * TIER2_THRESHOLD)
2154+
self.assertIsNotNone(ex)
2155+
uops = get_opnames(ex)
2156+
self.assertIn("_GUARD_TYPE_VERSION", uops)
2157+
self.assertNotIn("_CHECK_ATTR_CLASS", uops)
2158+
20962159

20972160
def global_identity(x):
20982161
return x

Lib/test/test_pyrepl/test_pyrepl.py

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import subprocess
99
import sys
1010
import tempfile
11+
from pkgutil import ModuleInfo
1112
from unittest import TestCase, skipUnless, skipIf
1213
from unittest.mock import patch
1314
from test.support import force_not_colorized, make_clean_env, Py_DEBUG
@@ -959,6 +960,46 @@ def test_import_completions(self):
959960
output = reader.readline()
960961
self.assertEqual(output, expected)
961962

963+
@patch("pkgutil.iter_modules", lambda: [ModuleInfo(None, "public", True),
964+
ModuleInfo(None, "_private", True)])
965+
@patch("sys.builtin_module_names", ())
966+
def test_private_completions(self):
967+
cases = (
968+
# Return public methods by default
969+
("import \t\n", "import public"),
970+
("from \t\n", "from public"),
971+
# Return private methods if explicitly specified
972+
("import _\t\n", "import _private"),
973+
("from _\t\n", "from _private"),
974+
)
975+
for code, expected in cases:
976+
with self.subTest(code=code):
977+
events = code_to_events(code)
978+
reader = self.prepare_reader(events, namespace={})
979+
output = reader.readline()
980+
self.assertEqual(output, expected)
981+
982+
@patch(
983+
"_pyrepl._module_completer.ModuleCompleter.iter_submodules",
984+
lambda *_: [
985+
ModuleInfo(None, "public", True),
986+
ModuleInfo(None, "_private", True),
987+
],
988+
)
989+
def test_sub_module_private_completions(self):
990+
cases = (
991+
# Return public methods by default
992+
("from foo import \t\n", "from foo import public"),
993+
# Return private methods if explicitly specified
994+
("from foo import _\t\n", "from foo import _private"),
995+
)
996+
for code, expected in cases:
997+
with self.subTest(code=code):
998+
events = code_to_events(code)
999+
reader = self.prepare_reader(events, namespace={})
1000+
output = reader.readline()
1001+
self.assertEqual(output, expected)
1002+
9621003
def test_builtin_completion_top_level(self):
9631004
import importlib
9641005
# Make iter_modules() search only the standard library.
@@ -991,8 +1032,8 @@ def test_relative_import_completions(self):
9911032
output = reader.readline()
9921033
self.assertEqual(output, expected)
9931034

994-
@patch("pkgutil.iter_modules", lambda: [(None, 'valid_name', None),
995-
(None, 'invalid-name', None)])
1035+
@patch("pkgutil.iter_modules", lambda: [ModuleInfo(None, "valid_name", True),
1036+
ModuleInfo(None, "invalid-name", True)])
9961037
def test_invalid_identifiers(self):
9971038
# Make sure modules which are not valid identifiers
9981039
# are not suggested as those cannot be imported via 'import'.

Lib/test/test_zipfile/test_core.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1991,6 +1991,25 @@ def test_is_zip_erroneous_file(self):
19911991
self.assertFalse(zipfile.is_zipfile(fp))
19921992
fp.seek(0, 0)
19931993
self.assertFalse(zipfile.is_zipfile(fp))
1994+
# - passing non-zipfile with ZIP header elements
1995+
# data created using pyPNG like so:
1996+
# d = [(ord('P'), ord('K'), 5, 6), (ord('P'), ord('K'), 6, 6)]
1997+
# w = png.Writer(1,2,alpha=True,compression=0)
1998+
# f = open('onepix.png', 'wb')
1999+
# w.write(f, d)
2000+
# w.close()
2001+
data = (b"\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x01\x00\x00"
2002+
b"\x00\x02\x08\x06\x00\x00\x00\x99\x81\xb6'\x00\x00\x00\x15I"
2003+
b"DATx\x01\x01\n\x00\xf5\xff\x00PK\x05\x06\x00PK\x06\x06\x07"
2004+
b"\xac\x01N\xc6|a\r\x00\x00\x00\x00IEND\xaeB`\x82")
2005+
# - passing a filename
2006+
with open(TESTFN, "wb") as fp:
2007+
fp.write(data)
2008+
self.assertFalse(zipfile.is_zipfile(TESTFN))
2009+
# - passing a file-like object
2010+
fp = io.BytesIO()
2011+
fp.write(data)
2012+
self.assertFalse(zipfile.is_zipfile(fp))
19942013

19952014
def test_damaged_zipfile(self):
19962015
"""Check that zipfiles with missing bytes at the end raise BadZipFile."""

0 commit comments

Comments
 (0)