Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into move_lltrace_to_frame
Browse files Browse the repository at this point in the history
  • Loading branch information
Fidget-Spinner committed Jan 21, 2025
2 parents 732c6b4 + f5b6356 commit c7bdb4f
Show file tree
Hide file tree
Showing 43 changed files with 415 additions and 295 deletions.
2 changes: 1 addition & 1 deletion Doc/howto/mro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ with inheritance diagram
We see that class G inherits from F and E, with F *before* E: therefore
we would expect the attribute *G.remember2buy* to be inherited by
*F.rembermer2buy* and not by *E.remember2buy*: nevertheless Python 2.2
*F.remember2buy* and not by *E.remember2buy*: nevertheless Python 2.2
gives

>>> G.remember2buy # doctest: +SKIP
Expand Down
4 changes: 2 additions & 2 deletions Doc/library/ctypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@ Fundamental data types
(1)
The constructor accepts any object with a truth value.

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

+----------------------------------+---------------------------------+-----------------+
| ctypes type | C type | Python type |
Expand Down
9 changes: 5 additions & 4 deletions Include/cpython/code.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ typedef struct {
} _PyCoCached;

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


Expand Down
5 changes: 3 additions & 2 deletions Include/internal/pycore_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ enum _frameowner {
FRAME_OWNED_BY_THREAD = 0,
FRAME_OWNED_BY_GENERATOR = 1,
FRAME_OWNED_BY_FRAME_OBJECT = 2,
FRAME_OWNED_BY_CSTACK = 3,
FRAME_OWNED_BY_INTERPRETER = 3,
FRAME_OWNED_BY_CSTACK = 4,
};

typedef struct _PyInterpreterFrame {
Expand Down Expand Up @@ -269,7 +270,7 @@ _PyFrame_SetStackPointer(_PyInterpreterFrame *frame, _PyStackRef *stack_pointer)
static inline bool
_PyFrame_IsIncomplete(_PyInterpreterFrame *frame)
{
if (frame->owner == FRAME_OWNED_BY_CSTACK) {
if (frame->owner >= FRAME_OWNED_BY_INTERPRETER) {
return true;
}
return frame->owner != FRAME_OWNED_BY_GENERATOR &&
Expand Down
6 changes: 5 additions & 1 deletion Lib/test/test__colorize.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


def setUpModule():
_colorize.can_colorize = lambda: False
_colorize.can_colorize = lambda *args, **kwargs: False


def tearDownModule():
Expand All @@ -21,6 +21,7 @@ class TestColorizeFunction(unittest.TestCase):
def test_colorized_detection_checks_for_environment_variables(self):
flags = unittest.mock.MagicMock(ignore_environment=False)
with (unittest.mock.patch("os.isatty") as isatty_mock,
unittest.mock.patch("sys.stdout") as stdout_mock,
unittest.mock.patch("sys.stderr") as stderr_mock,
unittest.mock.patch("sys.flags", flags),
unittest.mock.patch("_colorize.can_colorize", ORIGINAL_CAN_COLORIZE),
Expand All @@ -29,6 +30,8 @@ def test_colorized_detection_checks_for_environment_variables(self):
contextlib.nullcontext()) as vt_mock):

isatty_mock.return_value = True
stdout_mock.fileno.return_value = 1
stdout_mock.isatty.return_value = True
stderr_mock.fileno.return_value = 2
stderr_mock.isatty.return_value = True
with unittest.mock.patch("os.environ", {'TERM': 'dumb'}):
Expand Down Expand Up @@ -61,6 +64,7 @@ def test_colorized_detection_checks_for_environment_variables(self):
self.assertEqual(_colorize.can_colorize(), True)

isatty_mock.return_value = False
stdout_mock.isatty.return_value = False
stderr_mock.isatty.return_value = False
self.assertEqual(_colorize.can_colorize(), False)

Expand Down
18 changes: 18 additions & 0 deletions Lib/test/test_ctypes/test_c_simple_type_meta.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import unittest
from test.support import MS_WINDOWS
import ctypes
from ctypes import POINTER, c_void_p

Expand Down Expand Up @@ -150,3 +151,20 @@ class Sub(CtBase):

self.assertIsInstance(POINTER(Sub), p_meta)
self.assertIsSubclass(POINTER(Sub), Sub)

def test_bad_type_message(self):
"""Verify the error message that lists all available type codes"""
# (The string is generated at runtime, so this checks the underlying
# set of types as well as correct construction of the string.)
with self.assertRaises(AttributeError) as cm:
class F(metaclass=PyCSimpleType):
_type_ = "\0"
message = str(cm.exception)
expected_type_chars = list('cbBhHiIlLdCEFfuzZqQPXOv?g')
if not hasattr(ctypes, 'c_float_complex'):
expected_type_chars.remove('C')
expected_type_chars.remove('E')
expected_type_chars.remove('F')
if not MS_WINDOWS:
expected_type_chars.remove('X')
self.assertIn("'" + ''.join(expected_type_chars) + "'", message)
14 changes: 7 additions & 7 deletions Lib/test/test_import/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ def test_import_name_binding(self):
import test as x
import test.support
self.assertIs(x, test, x.__name__)
self.assertTrue(hasattr(test.support, "__file__"))
self.assertHasAttr(test.support, "__file__")

# import x.y.z as w binds z as w
import test.support as y
Expand Down Expand Up @@ -610,7 +610,7 @@ def test_file_to_source(self):
sys.path.insert(0, os.curdir)
try:
mod = __import__(TESTFN)
self.assertTrue(mod.__file__.endswith('.py'))
self.assertEndsWith(mod.__file__, '.py')
os.remove(source)
del sys.modules[TESTFN]
make_legacy_pyc(source)
Expand Down Expand Up @@ -1443,7 +1443,7 @@ def test_UNC_path(self):
self.fail("could not import 'test_unc_path' from %r: %r"
% (unc, e))
self.assertEqual(mod.testdata, 'test_unc_path')
self.assertTrue(mod.__file__.startswith(unc), mod.__file__)
self.assertStartsWith(mod.__file__, unc)
unload("test_unc_path")


Expand All @@ -1456,7 +1456,7 @@ def tearDown(self):
def test_relimport_star(self):
# This will import * from .test_import.
from .. import relimport
self.assertTrue(hasattr(relimport, "RelativeImportTests"))
self.assertHasAttr(relimport, "RelativeImportTests")

def test_issue3221(self):
# Note for mergers: the 'absolute' tests from the 2.x branch
Expand Down Expand Up @@ -1786,15 +1786,15 @@ def test_frozen_importlib_is_bootstrap(self):
self.assertIs(mod, _bootstrap)
self.assertEqual(mod.__name__, 'importlib._bootstrap')
self.assertEqual(mod.__package__, 'importlib')
self.assertTrue(mod.__file__.endswith('_bootstrap.py'), mod.__file__)
self.assertEndsWith(mod.__file__, '_bootstrap.py')

def test_frozen_importlib_external_is_bootstrap_external(self):
from importlib import _bootstrap_external
mod = sys.modules['_frozen_importlib_external']
self.assertIs(mod, _bootstrap_external)
self.assertEqual(mod.__name__, 'importlib._bootstrap_external')
self.assertEqual(mod.__package__, 'importlib')
self.assertTrue(mod.__file__.endswith('_bootstrap_external.py'), mod.__file__)
self.assertEndsWith(mod.__file__, '_bootstrap_external.py')

def test_there_can_be_only_one(self):
# Issue #15386 revealed a tricky loophole in the bootstrapping
Expand Down Expand Up @@ -2800,7 +2800,7 @@ def check_common(self, loaded):
self.assertEqual(mod.__file__, self.FILE)
self.assertEqual(mod.__spec__.origin, self.ORIGIN)
if not isolated:
self.assertTrue(issubclass(mod.error, Exception))
self.assertIsSubclass(mod.error, Exception)
self.assertEqual(mod.int_const, 1969)
self.assertEqual(mod.str_const, 'something different')
self.assertIsInstance(mod._module_initialized, float)
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_importlib/extension/test_path_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def hook(self, entry):
def test_success(self):
# Path hook should handle a directory where a known extension module
# exists.
self.assertTrue(hasattr(self.hook(util.EXTENSIONS.path), 'find_spec'))
self.assertHasAttr(self.hook(util.EXTENSIONS.path), 'find_spec')


(Frozen_PathHooksTests,
Expand Down
6 changes: 3 additions & 3 deletions Lib/test/test_importlib/frozen/test_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def exec_module(self, name, origname=None):
module.main()

self.assertTrue(module.initialized)
self.assertTrue(hasattr(module, '__spec__'))
self.assertHasAttr(module, '__spec__')
self.assertEqual(module.__spec__.origin, 'frozen')
return module, stdout.getvalue()

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

def test_package(self):
Expand Down Expand Up @@ -136,7 +136,7 @@ def test_get_code(self):
exec(code, mod.__dict__)
with captured_stdout() as stdout:
mod.main()
self.assertTrue(hasattr(mod, 'initialized'))
self.assertHasAttr(mod, 'initialized')
self.assertEqual(stdout.getvalue(), 'Hello world!\n')

def test_get_source(self):
Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_importlib/import_/test_caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def test_using_cache_for_assigning_to_attribute(self):
with self.create_mock('pkg.__init__', 'pkg.module') as importer:
with util.import_state(meta_path=[importer]):
module = self.__import__('pkg.module')
self.assertTrue(hasattr(module, 'module'))
self.assertHasAttr(module, 'module')
self.assertEqual(id(module.module),
id(sys.modules['pkg.module']))

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

Expand Down
16 changes: 8 additions & 8 deletions Lib/test/test_importlib/import_/test_fromlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,23 @@ def test_nonexistent_object(self):
with util.import_state(meta_path=[importer]):
module = self.__import__('module', fromlist=['non_existent'])
self.assertEqual(module.__name__, 'module')
self.assertFalse(hasattr(module, 'non_existent'))
self.assertNotHasAttr(module, 'non_existent')

def test_module_from_package(self):
# [module]
with util.mock_spec('pkg.__init__', 'pkg.module') as importer:
with util.import_state(meta_path=[importer]):
module = self.__import__('pkg', fromlist=['module'])
self.assertEqual(module.__name__, 'pkg')
self.assertTrue(hasattr(module, 'module'))
self.assertHasAttr(module, 'module')
self.assertEqual(module.module.__name__, 'pkg.module')

def test_nonexistent_from_package(self):
with util.mock_spec('pkg.__init__') as importer:
with util.import_state(meta_path=[importer]):
module = self.__import__('pkg', fromlist=['non_existent'])
self.assertEqual(module.__name__, 'pkg')
self.assertFalse(hasattr(module, 'non_existent'))
self.assertNotHasAttr(module, 'non_existent')

def test_module_from_package_triggers_ModuleNotFoundError(self):
# If a submodule causes an ModuleNotFoundError because it tries
Expand Down Expand Up @@ -107,7 +107,7 @@ def basic_star_test(self, fromlist=['*']):
mock['pkg'].__all__ = ['module']
module = self.__import__('pkg', fromlist=fromlist)
self.assertEqual(module.__name__, 'pkg')
self.assertTrue(hasattr(module, 'module'))
self.assertHasAttr(module, 'module')
self.assertEqual(module.module.__name__, 'pkg.module')

def test_using_star(self):
Expand All @@ -125,8 +125,8 @@ def test_star_with_others(self):
mock['pkg'].__all__ = ['module1']
module = self.__import__('pkg', fromlist=['module2', '*'])
self.assertEqual(module.__name__, 'pkg')
self.assertTrue(hasattr(module, 'module1'))
self.assertTrue(hasattr(module, 'module2'))
self.assertHasAttr(module, 'module1')
self.assertHasAttr(module, 'module2')
self.assertEqual(module.module1.__name__, 'pkg.module1')
self.assertEqual(module.module2.__name__, 'pkg.module2')

Expand All @@ -136,15 +136,15 @@ def test_nonexistent_in_all(self):
importer['pkg'].__all__ = ['non_existent']
module = self.__import__('pkg', fromlist=['*'])
self.assertEqual(module.__name__, 'pkg')
self.assertFalse(hasattr(module, 'non_existent'))
self.assertNotHasAttr(module, 'non_existent')

def test_star_in_all(self):
with util.mock_spec('pkg.__init__') as importer:
with util.import_state(meta_path=[importer]):
importer['pkg'].__all__ = ['*']
module = self.__import__('pkg', fromlist=['*'])
self.assertEqual(module.__name__, 'pkg')
self.assertFalse(hasattr(module, '*'))
self.assertNotHasAttr(module, '*')

def test_invalid_type(self):
with util.mock_spec('pkg.__init__') as importer:
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_importlib/import_/test_meta_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test_empty(self):
self.assertIsNone(importlib._bootstrap._find_spec('nothing',
None))
self.assertEqual(len(w), 1)
self.assertTrue(issubclass(w[-1].category, ImportWarning))
self.assertIsSubclass(w[-1].category, ImportWarning)


(Frozen_CallingOrder,
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_importlib/import_/test_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def test_empty_path_hooks(self):
self.assertIsNone(self.find('os'))
self.assertIsNone(sys.path_importer_cache[path_entry])
self.assertEqual(len(w), 1)
self.assertTrue(issubclass(w[-1].category, ImportWarning))
self.assertIsSubclass(w[-1].category, ImportWarning)

def test_path_importer_cache_empty_string(self):
# The empty string should create a finder using the cwd.
Expand Down
6 changes: 3 additions & 3 deletions Lib/test/test_importlib/import_/test_relative_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def callback(global_):
self.__import__('pkg') # For __import__().
module = self.__import__('', global_, fromlist=['mod2'], level=1)
self.assertEqual(module.__name__, 'pkg')
self.assertTrue(hasattr(module, 'mod2'))
self.assertHasAttr(module, 'mod2')
self.assertEqual(module.mod2.attr, 'pkg.mod2')
self.relative_import_test(create, globals_, callback)

Expand All @@ -107,7 +107,7 @@ def callback(global_):
module = self.__import__('', global_, fromlist=['module'],
level=1)
self.assertEqual(module.__name__, 'pkg')
self.assertTrue(hasattr(module, 'module'))
self.assertHasAttr(module, 'module')
self.assertEqual(module.module.attr, 'pkg.module')
self.relative_import_test(create, globals_, callback)

Expand All @@ -131,7 +131,7 @@ def callback(global_):
module = self.__import__('', global_, fromlist=['subpkg2'],
level=2)
self.assertEqual(module.__name__, 'pkg')
self.assertTrue(hasattr(module, 'subpkg2'))
self.assertHasAttr(module, 'subpkg2')
self.assertEqual(module.subpkg2.attr, 'pkg.subpkg2.__init__')
self.relative_import_test(create, globals_, callback)

Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_importlib/resources/test_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test_reading(self):
target = resources.files(self.data) / 'utf-8.file'
with resources.as_file(target) as path:
self.assertIsInstance(path, pathlib.Path)
self.assertTrue(path.name.endswith("utf-8.file"), repr(path))
self.assertEndsWith(path.name, "utf-8.file")
self.assertEqual('Hello, UTF-8 world!\n', path.read_text(encoding='utf-8'))


Expand Down
8 changes: 4 additions & 4 deletions Lib/test/test_importlib/source/test_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def run_test(self, test, create=None, *, compile_=None, unlink=None):
if error.errno != errno.ENOENT:
raise
loader = self.import_(mapping['.root'], test)
self.assertTrue(hasattr(loader, 'load_module'))
self.assertHasAttr(loader, 'load_module')
return loader

def test_module(self):
Expand All @@ -100,15 +100,15 @@ def test_module_in_package(self):
with util.create_modules('pkg.__init__', 'pkg.sub') as mapping:
pkg_dir = os.path.dirname(mapping['pkg.__init__'])
loader = self.import_(pkg_dir, 'pkg.sub')
self.assertTrue(hasattr(loader, 'load_module'))
self.assertHasAttr(loader, 'load_module')

# [sub package]
def test_package_in_package(self):
context = util.create_modules('pkg.__init__', 'pkg.sub.__init__')
with context as mapping:
pkg_dir = os.path.dirname(mapping['pkg.__init__'])
loader = self.import_(pkg_dir, 'pkg.sub')
self.assertTrue(hasattr(loader, 'load_module'))
self.assertHasAttr(loader, 'load_module')

# [package over modules]
def test_package_over_module(self):
Expand All @@ -129,7 +129,7 @@ def test_empty_string_for_dir(self):
file.write("# test file for importlib")
try:
loader = self._find(finder, 'mod', loader_only=True)
self.assertTrue(hasattr(loader, 'load_module'))
self.assertHasAttr(loader, 'load_module')
finally:
os.unlink('mod.py')

Expand Down
Loading

0 comments on commit c7bdb4f

Please sign in to comment.