mirror of
https://github.com/python/cpython.git
synced 2025-11-01 02:38:53 +00:00
GH-122821: Simplify compilation of while statements to ensure consistency of offsets for sys.monitoring (GH-122934)
This commit is contained in:
parent
0e207f3e7a
commit
fe23f8ed97
6 changed files with 122 additions and 87 deletions
|
|
@ -1446,9 +1446,27 @@ class BranchRecorder(JumpRecorder):
|
|||
|
||||
|
||||
|
||||
class JumpOffsetRecorder:
|
||||
|
||||
event_type = E.JUMP
|
||||
name = "jump"
|
||||
|
||||
def __init__(self, events, offsets=False):
|
||||
self.events = events
|
||||
|
||||
def __call__(self, code, from_, to):
|
||||
self.events.append((self.name, code.co_name, from_, to))
|
||||
|
||||
class BranchOffsetRecorder(JumpOffsetRecorder):
|
||||
|
||||
event_type = E.BRANCH
|
||||
name = "branch"
|
||||
|
||||
|
||||
JUMP_AND_BRANCH_RECORDERS = JumpRecorder, BranchRecorder
|
||||
JUMP_BRANCH_AND_LINE_RECORDERS = JumpRecorder, BranchRecorder, LineRecorder
|
||||
FLOW_AND_LINE_RECORDERS = JumpRecorder, BranchRecorder, LineRecorder, ExceptionRecorder, ReturnRecorder
|
||||
BRANCH_OFFSET_RECORDERS = BranchOffsetRecorder,
|
||||
|
||||
class TestBranchAndJumpEvents(CheckEvents):
|
||||
maxDiff = None
|
||||
|
|
@ -1538,6 +1556,24 @@ class TestBranchAndJumpEvents(CheckEvents):
|
|||
('return', 'func', None),
|
||||
('line', 'get_events', 11)])
|
||||
|
||||
def test_while_offset_consistency(self):
|
||||
|
||||
def foo(n=0):
|
||||
while n<4:
|
||||
pass
|
||||
n += 1
|
||||
return None
|
||||
|
||||
in_loop = ('branch', 'foo', 10, 14)
|
||||
exit_loop = ('branch', 'foo', 10, 30)
|
||||
self.check_events(foo, recorders = BRANCH_OFFSET_RECORDERS, expected = [
|
||||
in_loop,
|
||||
in_loop,
|
||||
in_loop,
|
||||
in_loop,
|
||||
exit_loop])
|
||||
|
||||
|
||||
class TestLoadSuperAttr(CheckEvents):
|
||||
RECORDERS = CallRecorder, LineRecorder, CRaiseRecorder, CReturnRecorder
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue