Skip to content

Commit e0c1d04

Browse files
authored
Merge branch 'main' into ali/faulthandler-code-metadata
2 parents 2ce7ac6 + 1e8ff18 commit e0c1d04

26 files changed

Lines changed: 507 additions & 280 deletions

‎Doc/conf.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,10 @@
469469
# https://github.com/sphinx-doc/sphinx/issues/12359
470470
epub_use_index = False
471471

472+
# The default depth of 3 lists over a thousand entries, which makes the
473+
# table of contents hard to navigate in e-book readers
474+
epub_tocdepth = 2
475+
472476
# translation tag
473477
# ---------------
474478

‎Doc/library/dis.rst‎

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1899,32 +1899,38 @@ iterations of the loop.
18991899

19001900
The operand determines which intrinsic function is called:
19011901

1902-
+------------------------------------------+-----------------------------------+
1903-
| Operand | Description |
1904-
+==========================================+===================================+
1905-
| ``INTRINSIC_2_INVALID`` | Not valid |
1906-
+------------------------------------------+-----------------------------------+
1907-
| ``INTRINSIC_PREP_RERAISE_STAR`` | Calculates the |
1908-
| | :exc:`ExceptionGroup` to raise |
1909-
| | from a ``try-except*``. |
1910-
+------------------------------------------+-----------------------------------+
1911-
| ``INTRINSIC_TYPEVAR_WITH_BOUND`` | Creates a :class:`typing.TypeVar` |
1912-
| | with a bound. |
1913-
+------------------------------------------+-----------------------------------+
1914-
| ``INTRINSIC_TYPEVAR_WITH_CONSTRAINTS`` | Creates a |
1915-
| | :class:`typing.TypeVar` with |
1916-
| | constraints. |
1917-
+------------------------------------------+-----------------------------------+
1918-
| ``INTRINSIC_SET_FUNCTION_TYPE_PARAMS`` | Sets the ``__type_params__`` |
1919-
| | attribute of a function. |
1920-
+------------------------------------------+-----------------------------------+
1921-
| ``INTRINSIC_ADD_CONDITIONAL_ANNOTATION`` | Adds an annotation index to the |
1922-
| | ``__conditional_annotations__`` |
1923-
| | set. |
1924-
+------------------------------------------+-----------------------------------+
1902+
+------------------------------------------+-----------------------------------------+
1903+
| Operand | Description |
1904+
+==========================================+=========================================+
1905+
| ``INTRINSIC_2_INVALID`` | Not valid |
1906+
+------------------------------------------+-----------------------------------------+
1907+
| ``INTRINSIC_PREP_RERAISE_STAR`` | Calculates the |
1908+
| | :exc:`ExceptionGroup` to raise |
1909+
| | from a ``try-except*``. |
1910+
+------------------------------------------+-----------------------------------------+
1911+
| ``INTRINSIC_TYPEVAR_WITH_BOUND`` | Creates a :class:`typing.TypeVar` |
1912+
| | with a bound. |
1913+
+------------------------------------------+-----------------------------------------+
1914+
| ``INTRINSIC_TYPEVAR_WITH_CONSTRAINTS`` | Creates a |
1915+
| | :class:`typing.TypeVar` with |
1916+
| | constraints. |
1917+
+------------------------------------------+-----------------------------------------+
1918+
| ``INTRINSIC_SET_FUNCTION_TYPE_PARAMS`` | Sets the ``__type_params__`` |
1919+
| | attribute of a function. |
1920+
+------------------------------------------+-----------------------------------------+
1921+
| ``INTRINSIC_ADD_CONDITIONAL_ANNOTATION`` | Adds an annotation index to the |
1922+
| | ``__conditional_annotations__`` |
1923+
| | set. |
1924+
+------------------------------------------+-----------------------------------------+
1925+
| ``INTRINSIC_MATCH_CLASS_ISINSTANCE`` | Do :func:`isinstance` checks for |
1926+
| | :ref:`Class patterns <class-patterns>`. |
1927+
+------------------------------------------+-----------------------------------------+
19251928

19261929
.. versionadded:: 3.12
19271930

1931+
.. versionchanged:: 3.16
1932+
Added ``INTRINSIC_MATCH_CLASS_ISINSTANCE``.
1933+
19281934

19291935
.. opcode:: LOAD_SPECIAL
19301936

‎Doc/library/optparse.rst‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,12 @@ Choosing an argument parsing library
1616
The standard library includes three argument parsing libraries:
1717

1818
* :mod:`getopt`: a module that closely mirrors the procedural C ``getopt`` API.
19-
Included in the standard library since before the initial Python 1.0 release.
2019
* :mod:`!optparse`: a declarative replacement for ``getopt`` that
2120
provides equivalent functionality without requiring each application
22-
to implement its own procedural option parsing logic. Included
23-
in the standard library since the Python 2.3 release.
21+
to implement its own procedural option parsing logic.
2422
* :mod:`argparse`: a more opinionated alternative to ``optparse`` that
2523
provides more functionality by default, at the expense of reduced application
26-
flexibility in controlling exactly how arguments are processed. Included in
27-
the standard library since the Python 2.7 and Python 3.2 releases.
24+
flexibility in controlling exactly how arguments are processed.
2825

2926
In the absence of more specific argument parsing design constraints, :mod:`argparse`
3027
is the recommended choice for implementing command line applications, as it offers

‎Include/internal/pycore_intrinsics.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@
3131
#define INTRINSIC_SET_FUNCTION_TYPE_PARAMS 4
3232
#define INTRINSIC_SET_TYPEPARAM_DEFAULT 5
3333
#define INTRINSIC_ADD_CONDITIONAL_ANNOTATION 6
34+
#define INTRINSIC_MATCH_CLASS_ISINSTANCE 7
3435

35-
#define MAX_INTRINSIC_2 6
36+
#define MAX_INTRINSIC_2 7
3637

3738
typedef PyObject *(*intrinsic_func1)(PyThreadState* tstate, PyObject *value);
3839
typedef PyObject *(*intrinsic_func2)(PyThreadState* tstate, PyObject *value1, PyObject *value2);

‎Lib/_ast_unparse.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,11 @@ def visit_Attribute(self, node):
925925
# Special case: 3.__abs__() is a syntax error, so if node.value
926926
# is an integer literal then we need to either parenthesize
927927
# it or add an extra space to get 3 .__abs__().
928-
if isinstance(node.value, Constant) and isinstance(node.value.value, int):
928+
# bool is a subclass of int, but True.real and False.real are
929+
# valid without a space.
930+
if (isinstance(node.value, Constant)
931+
and isinstance(node.value.value, int)
932+
and not isinstance(node.value.value, bool)):
929933
self.write(" ")
930934
self.write(".")
931935
self.write(node.attr)

‎Lib/optparse.py‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
"""A powerful, extensible, and easy-to-use option parser.
22
3-
By Greg Ward <gward@python.net>
4-
5-
Originally distributed as Optik.
6-
7-
For support, use the optik-users@lists.sourceforge.net mailing list
8-
(http://lists.sourceforge.net/lists/listinfo/optik-users).
9-
103
Simple usage example:
114
125
from optparse import OptionParser

‎Lib/test/lazy_imports_all_exclude.txt‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,5 @@ test_pyrepl
3535
test_subprocess
3636
test_symtable
3737
test_tools
38-
test_trace
3938
test_type_annotations
4039
test_unittest

‎Lib/test/test_capi/test_opt.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5752,12 +5752,13 @@ def testfunc(n):
57525752
def test_match_class(self):
57535753
def testfunc(n):
57545754
class A:
5755+
__match_args__ = ("val",)
57555756
val = 1
57565757
x = A()
57575758
ret = 0
57585759
for _ in range(n):
57595760
match x:
5760-
case A():
5761+
case A(1):
57615762
ret += x.val
57625763
return ret
57635764

@@ -5766,7 +5767,7 @@ class A:
57665767
uops = get_opnames(ex)
57675768

57685769
self.assertIn("_MATCH_CLASS", uops)
5769-
self.assertEqual(count_ops(ex, "_POP_TOP_NOP"), 4)
5770+
self.assertEqual(count_ops(ex, "_POP_TOP_NOP"), 5)
57705771

57715772
def test_dict_update(self):
57725773
def testfunc(n):

‎Lib/test/test_cext/__init__.py‎

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
os.path.join(SOURCE_DIR, 'extension.cpp'),
2727
os.path.join(SOURCE_DIR, 'setup.py'),
2828
]
29+
RUNTESTS_PY = os.path.join(SOURCE_DIR, 'runtests.py')
2930
MSVC = support.MS_WINDOWS
3031

3132

@@ -99,21 +100,10 @@ def run_cmd(operation, cmd):
99100
cmd.append('-v')
100101
run_cmd('Install', cmd)
101102

102-
# Do a reference run. Until we test that running python
103-
# doesn't leak references (gh-94755), run it so one can manually check
104-
# -X showrefcount results against this baseline.
105-
cmd = [python_exe,
106-
'-X', 'dev',
107-
'-X', 'showrefcount',
108-
'-c', 'pass']
109-
run_cmd('Reference run', cmd)
110-
111-
# Import the C/C++ extension
112-
cmd = [python_exe,
113-
'-X', 'dev',
114-
'-X', 'showrefcount',
115-
'-c', f"import {extension_name}"]
116-
run_cmd('Import', cmd)
103+
# Import the extension module and run tests.
104+
# On a debug build, check also for reference leaks.
105+
cmd = [python_exe, '-X', 'dev', RUNTESTS_PY, extension_name]
106+
run_cmd('Tests', cmd)
117107

118108

119109
class TestPublicC(BaseTests, unittest.TestCase):

‎Lib/test/test_cext/extension.c‎

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,11 @@ class VirtualPyObject : public PyObject {
264264
public:
265265
VirtualPyObject();
266266
virtual ~VirtualPyObject() {
267+
PyTypeObject *type = Py_TYPE(this);
267268
delete [] internal_data;
268269
--instance_count;
270+
// Do not call type->tp_free(this), C++ manages the memory
271+
Py_DECREF(type);
269272
}
270273
virtual void set_internal_data() {
271274
internal_data[0] = 1;
@@ -295,7 +298,7 @@ _Py_COMP_DIAG_PUSH
295298
#endif
296299

297300
PyType_Slot VirtualPyObject_Slots[] = {
298-
{Py_tp_free, (void*)VirtualPyObject::dealloc},
301+
{Py_tp_dealloc, (void*)VirtualPyObject::dealloc},
299302
{0, _Py_NULL},
300303
};
301304

@@ -333,6 +336,10 @@ test_virtual_object(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args))
333336
"instance_count should be 0, got %d",
334337
VirtualPyObject::instance_count);
335338
}
339+
340+
// Force a garbage collection to delete the temporary heap type
341+
// used by this test
342+
PyGC_Collect();
336343
Py_RETURN_NONE;
337344
}
338345
#endif // __cplusplus && !Py_TARGET_ABI3T
@@ -356,8 +363,6 @@ static PyMethodDef module_methods[] = {
356363
static int
357364
module_exec(PyObject *module)
358365
{
359-
PyObject *result;
360-
361366
#ifdef __STDC_VERSION__
362367
if (PyModule_AddIntMacro(module, __STDC_VERSION__) < 0) {
363368
return -1;
@@ -368,31 +373,13 @@ module_exec(PyObject *module)
368373
return -1;
369374
}
370375
#endif
371-
372-
result = PyObject_CallMethod(module, "test_macros", "");
373-
if (!result) return -1;
374-
Py_DECREF(result);
375-
376-
result = PyObject_CallMethod(module, "test_datetime", "");
377-
if (!result) return -1;
378-
Py_DECREF(result);
379-
380-
result = PyObject_CallMethod(module, "test_unicode", "");
381-
if (!result) return -1;
382-
Py_DECREF(result);
383-
384-
#ifdef __cplusplus
385-
result = PyObject_CallMethod(module, "test_api_casts", "");
386-
if (!result) return -1;
387-
Py_DECREF(result);
388-
#endif
389-
390-
#if defined(__cplusplus) && !defined(Py_TARGET_ABI3T)
391-
result = PyObject_CallMethod(module, "test_virtual_object", "");
392-
if (!result) return -1;
393-
Py_DECREF(result);
376+
#ifdef _MSVC_LANG
377+
if (PyModule_AddIntMacro(module, _MSVC_LANG) < 0) {
378+
return -1;
379+
}
394380
#endif
395-
381+
// Ignore "unused argument" warning when none of these macros is defined
382+
(void)module;
396383
return 0;
397384
}
398385

0 commit comments

Comments
 (0)