Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Feedback from code review
  • Loading branch information
brandtbucher committed Jun 16, 2022
commit 8266ba9c658609a25cbe15dd66bc63b4f58878f1
18 changes: 11 additions & 7 deletions Lib/test/test_dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1756,20 +1756,24 @@ def test_co_positions_missing_info(self):
@requires_debug_ranges()
def test_co_positions_with_lots_of_caches(self):
def roots(a, b, c):
d = (b**2 - 4 * a * c) ** 0.5
yield (-b - d) / (2 * a)
d = b**2 - 4 * a * c
yield (-b - cmath.sqrt(d)) / (2 * a)
if d:
yield (-b + d) / (2 * a)
yield (-b + cmath.sqrt(d)) / (2 * a)
code = roots.__code__
ops = code.co_code[::2]
cache = opcode.opmap["CACHE"]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cache = opcode.opmap["CACHE"]
cache_opcode = opcode.opmap["CACHE"]

caches = sum(op == cache for op in ops)
non_caches = len(ops) - caches
# Make sure we have "lots of caches". If not, roots should be updated:
assert 1 / 3 <= caches / non_caches, "this test needs more caches!"
for show_caches in (False, True):
for adaptive in (False, True):
with self.subTest(f"{adaptive=}, {show_caches=}"):
co_positions = [
positions
for op, positions in zip(
code.co_code[::2], code.co_positions(), strict=True
)
if show_caches or op != opcode.opmap["CACHE"]
for op, positions in zip(ops, code.co_positions(), strict=True)
if show_caches or op != cache
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if show_caches or op != cache
if show_caches or op != cache_opcode

]
dis_positions = [
instruction.positions
Expand Down