Skip to content

Commit c7bdb4f

Browse files
Merge remote-tracking branch 'upstream/main' into move_lltrace_to_frame
2 parents 732c6b4 + f5b6356 commit c7bdb4f

Some content is hidden

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

43 files changed

+415
-295
lines changed

Doc/howto/mro.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ with inheritance diagram
398398
399399
We see that class G inherits from F and E, with F *before* E: therefore
400400
we would expect the attribute *G.remember2buy* to be inherited by
401-
*F.rembermer2buy* and not by *E.remember2buy*: nevertheless Python 2.2
401+
*F.remember2buy* and not by *E.remember2buy*: nevertheless Python 2.2
402402
gives
403403

404404
>>> G.remember2buy # doctest: +SKIP

Doc/library/ctypes.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,8 @@ Fundamental data types
266266
(1)
267267
The constructor accepts any object with a truth value.
268268

269-
Additionally, if IEC 60559 compatible complex arithmetic (Annex G) is supported, the following
270-
complex types are available:
269+
Additionally, if IEC 60559 compatible complex arithmetic (Annex G) is supported
270+
in both C and ``libffi``, the following complex types are available:
271271

272272
+----------------------------------+---------------------------------+-----------------+
273273
| ctypes type | C type | Python type |

Include/cpython/code.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@ typedef struct {
3535
} _PyCoCached;
3636

3737
/* Ancillary data structure used for instrumentation.
38-
Line instrumentation creates an array of
39-
these. One entry per code unit.*/
38+
Line instrumentation creates this with sufficient
39+
space for one entry per code unit. The total size
40+
of the data will be `bytes_per_entry * Py_SIZE(code)` */
4041
typedef struct {
41-
uint8_t original_opcode;
42-
int8_t line_delta;
42+
uint8_t bytes_per_entry;
43+
uint8_t data[1];
4344
} _PyCoLineInstrumentationData;
4445

4546

Include/internal/pycore_frame.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ enum _frameowner {
5656
FRAME_OWNED_BY_THREAD = 0,
5757
FRAME_OWNED_BY_GENERATOR = 1,
5858
FRAME_OWNED_BY_FRAME_OBJECT = 2,
59-
FRAME_OWNED_BY_CSTACK = 3,
59+
FRAME_OWNED_BY_INTERPRETER = 3,
60+
FRAME_OWNED_BY_CSTACK = 4,
6061
};
6162

6263
typedef struct _PyInterpreterFrame {
@@ -269,7 +270,7 @@ _PyFrame_SetStackPointer(_PyInterpreterFrame *frame, _PyStackRef *stack_pointer)
269270
static inline bool
270271
_PyFrame_IsIncomplete(_PyInterpreterFrame *frame)
271272
{
272-
if (frame->owner == FRAME_OWNED_BY_CSTACK) {
273+
if (frame->owner >= FRAME_OWNED_BY_INTERPRETER) {
273274
return true;
274275
}
275276
return frame->owner != FRAME_OWNED_BY_GENERATOR &&

Lib/test/test__colorize.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
def setUpModule():
12-
_colorize.can_colorize = lambda: False
12+
_colorize.can_colorize = lambda *args, **kwargs: False
1313

1414

1515
def tearDownModule():
@@ -21,6 +21,7 @@ class TestColorizeFunction(unittest.TestCase):
2121
def test_colorized_detection_checks_for_environment_variables(self):
2222
flags = unittest.mock.MagicMock(ignore_environment=False)
2323
with (unittest.mock.patch("os.isatty") as isatty_mock,
24+
unittest.mock.patch("sys.stdout") as stdout_mock,
2425
unittest.mock.patch("sys.stderr") as stderr_mock,
2526
unittest.mock.patch("sys.flags", flags),
2627
unittest.mock.patch("_colorize.can_colorize", ORIGINAL_CAN_COLORIZE),
@@ -29,6 +30,8 @@ def test_colorized_detection_checks_for_environment_variables(self):
2930
contextlib.nullcontext()) as vt_mock):
3031

3132
isatty_mock.return_value = True
33+
stdout_mock.fileno.return_value = 1
34+
stdout_mock.isatty.return_value = True
3235
stderr_mock.fileno.return_value = 2
3336
stderr_mock.isatty.return_value = True
3437
with unittest.mock.patch("os.environ", {'TERM': 'dumb'}):
@@ -61,6 +64,7 @@ def test_colorized_detection_checks_for_environment_variables(self):
6164
self.assertEqual(_colorize.can_colorize(), True)
6265

6366
isatty_mock.return_value = False
67+
stdout_mock.isatty.return_value = False
6468
stderr_mock.isatty.return_value = False
6569
self.assertEqual(_colorize.can_colorize(), False)
6670

Lib/test/test_ctypes/test_c_simple_type_meta.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import unittest
2+
from test.support import MS_WINDOWS
23
import ctypes
34
from ctypes import POINTER, c_void_p
45

@@ -150,3 +151,20 @@ class Sub(CtBase):
150151

151152
self.assertIsInstance(POINTER(Sub), p_meta)
152153
self.assertIsSubclass(POINTER(Sub), Sub)
154+
155+
def test_bad_type_message(self):
156+
"""Verify the error message that lists all available type codes"""
157+
# (The string is generated at runtime, so this checks the underlying
158+
# set of types as well as correct construction of the string.)
159+
with self.assertRaises(AttributeError) as cm:
160+
class F(metaclass=PyCSimpleType):
161+
_type_ = "\0"
162+
message = str(cm.exception)
163+
expected_type_chars = list('cbBhHiIlLdCEFfuzZqQPXOv?g')
164+
if not hasattr(ctypes, 'c_float_complex'):
165+
expected_type_chars.remove('C')
166+
expected_type_chars.remove('E')
167+
expected_type_chars.remove('F')
168+
if not MS_WINDOWS:
169+
expected_type_chars.remove('X')
170+
self.assertIn("'" + ''.join(expected_type_chars) + "'", message)

Lib/test/test_import/__init__.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ def test_import_name_binding(self):
539539
import test as x
540540
import test.support
541541
self.assertIs(x, test, x.__name__)
542-
self.assertTrue(hasattr(test.support, "__file__"))
542+
self.assertHasAttr(test.support, "__file__")
543543

544544
# import x.y.z as w binds z as w
545545
import test.support as y
@@ -610,7 +610,7 @@ def test_file_to_source(self):
610610
sys.path.insert(0, os.curdir)
611611
try:
612612
mod = __import__(TESTFN)
613-
self.assertTrue(mod.__file__.endswith('.py'))
613+
self.assertEndsWith(mod.__file__, '.py')
614614
os.remove(source)
615615
del sys.modules[TESTFN]
616616
make_legacy_pyc(source)
@@ -1443,7 +1443,7 @@ def test_UNC_path(self):
14431443
self.fail("could not import 'test_unc_path' from %r: %r"
14441444
% (unc, e))
14451445
self.assertEqual(mod.testdata, 'test_unc_path')
1446-
self.assertTrue(mod.__file__.startswith(unc), mod.__file__)
1446+
self.assertStartsWith(mod.__file__, unc)
14471447
unload("test_unc_path")
14481448

14491449

@@ -1456,7 +1456,7 @@ def tearDown(self):
14561456
def test_relimport_star(self):
14571457
# This will import * from .test_import.
14581458
from .. import relimport
1459-
self.assertTrue(hasattr(relimport, "RelativeImportTests"))
1459+
self.assertHasAttr(relimport, "RelativeImportTests")
14601460

14611461
def test_issue3221(self):
14621462
# Note for mergers: the 'absolute' tests from the 2.x branch
@@ -1786,15 +1786,15 @@ def test_frozen_importlib_is_bootstrap(self):
17861786
self.assertIs(mod, _bootstrap)
17871787
self.assertEqual(mod.__name__, 'importlib._bootstrap')
17881788
self.assertEqual(mod.__package__, 'importlib')
1789-
self.assertTrue(mod.__file__.endswith('_bootstrap.py'), mod.__file__)
1789+
self.assertEndsWith(mod.__file__, '_bootstrap.py')
17901790

17911791
def test_frozen_importlib_external_is_bootstrap_external(self):
17921792
from importlib import _bootstrap_external
17931793
mod = sys.modules['_frozen_importlib_external']
17941794
self.assertIs(mod, _bootstrap_external)
17951795
self.assertEqual(mod.__name__, 'importlib._bootstrap_external')
17961796
self.assertEqual(mod.__package__, 'importlib')
1797-
self.assertTrue(mod.__file__.endswith('_bootstrap_external.py'), mod.__file__)
1797+
self.assertEndsWith(mod.__file__, '_bootstrap_external.py')
17981798

17991799
def test_there_can_be_only_one(self):
18001800
# Issue #15386 revealed a tricky loophole in the bootstrapping
@@ -2800,7 +2800,7 @@ def check_common(self, loaded):
28002800
self.assertEqual(mod.__file__, self.FILE)
28012801
self.assertEqual(mod.__spec__.origin, self.ORIGIN)
28022802
if not isolated:
2803-
self.assertTrue(issubclass(mod.error, Exception))
2803+
self.assertIsSubclass(mod.error, Exception)
28042804
self.assertEqual(mod.int_const, 1969)
28052805
self.assertEqual(mod.str_const, 'something different')
28062806
self.assertIsInstance(mod._module_initialized, float)

Lib/test/test_importlib/extension/test_path_hook.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def hook(self, entry):
2121
def test_success(self):
2222
# Path hook should handle a directory where a known extension module
2323
# exists.
24-
self.assertTrue(hasattr(self.hook(util.EXTENSIONS.path), 'find_spec'))
24+
self.assertHasAttr(self.hook(util.EXTENSIONS.path), 'find_spec')
2525

2626

2727
(Frozen_PathHooksTests,

Lib/test/test_importlib/frozen/test_loader.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def exec_module(self, name, origname=None):
6161
module.main()
6262

6363
self.assertTrue(module.initialized)
64-
self.assertTrue(hasattr(module, '__spec__'))
64+
self.assertHasAttr(module, '__spec__')
6565
self.assertEqual(module.__spec__.origin, 'frozen')
6666
return module, stdout.getvalue()
6767

@@ -72,7 +72,7 @@ def test_module(self):
7272
for attr, value in check.items():
7373
self.assertEqual(getattr(module, attr), value)
7474
self.assertEqual(output, 'Hello world!\n')
75-
self.assertTrue(hasattr(module, '__spec__'))
75+
self.assertHasAttr(module, '__spec__')
7676
self.assertEqual(module.__spec__.loader_state.origname, name)
7777

7878
def test_package(self):
@@ -136,7 +136,7 @@ def test_get_code(self):
136136
exec(code, mod.__dict__)
137137
with captured_stdout() as stdout:
138138
mod.main()
139-
self.assertTrue(hasattr(mod, 'initialized'))
139+
self.assertHasAttr(mod, 'initialized')
140140
self.assertEqual(stdout.getvalue(), 'Hello world!\n')
141141

142142
def test_get_source(self):

Lib/test/test_importlib/import_/test_caching.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def test_using_cache_for_assigning_to_attribute(self):
7878
with self.create_mock('pkg.__init__', 'pkg.module') as importer:
7979
with util.import_state(meta_path=[importer]):
8080
module = self.__import__('pkg.module')
81-
self.assertTrue(hasattr(module, 'module'))
81+
self.assertHasAttr(module, 'module')
8282
self.assertEqual(id(module.module),
8383
id(sys.modules['pkg.module']))
8484

@@ -88,7 +88,7 @@ def test_using_cache_for_fromlist(self):
8888
with self.create_mock('pkg.__init__', 'pkg.module') as importer:
8989
with util.import_state(meta_path=[importer]):
9090
module = self.__import__('pkg', fromlist=['module'])
91-
self.assertTrue(hasattr(module, 'module'))
91+
self.assertHasAttr(module, 'module')
9292
self.assertEqual(id(module.module),
9393
id(sys.modules['pkg.module']))
9494

0 commit comments

Comments
 (0)