MCPcopy Index your code
hub / github.com/python/cpython / test_load_super_attr

Method test_load_super_attr

Lib/test/test_opcache.py:1501–1536  ·  view source on GitHub ↗

Ensure that LOAD_SUPER_ATTR is specialized as expected.

(self)

Source from the content-addressed store, hash-verified

1499 @cpython_only
1500 @requires_specialization
1501 def test_load_super_attr(self):
1502 """Ensure that LOAD_SUPER_ATTR is specialized as expected."""
1503
1504 class A:
1505 def __init__(self):
1506 meth = super().__init__
1507 super().__init__()
1508
1509 for _ in range(_testinternalcapi.SPECIALIZATION_THRESHOLD):
1510 A()
1511
1512 self.assert_specialized(A.__init__, "LOAD_SUPER_ATTR_ATTR")
1513 self.assert_specialized(A.__init__, "LOAD_SUPER_ATTR_METHOD")
1514 self.assert_no_opcode(A.__init__, "LOAD_SUPER_ATTR")
1515
1516 # Temporarily replace super() with something else.
1517 real_super = super
1518
1519 def fake_super():
1520 def init(self):
1521 pass
1522
1523 return init
1524
1525 # Force unspecialize
1526 globals()['super'] = fake_super
1527 try:
1528 # Should be unspecialized after enough calls.
1529 for _ in range(_testinternalcapi.SPECIALIZATION_COOLDOWN):
1530 A()
1531 finally:
1532 globals()['super'] = real_super
1533
1534 # Ensure the specialized instructions are not present
1535 self.assert_no_opcode(A.__init__, "LOAD_SUPER_ATTR_ATTR")
1536 self.assert_no_opcode(A.__init__, "LOAD_SUPER_ATTR_METHOD")
1537
1538 @cpython_only
1539 @requires_specialization

Callers

nothing calls this directly

Calls 3

assert_specializedMethod · 0.80
assert_no_opcodeMethod · 0.80
AClass · 0.70

Tested by

no test coverage detected