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

Method _exec_super

Lib/test/test_monitoring.py:1868–1880  ·  view source on GitHub ↗
(self, codestr, optimized=False)

Source from the content-addressed store, hash-verified

1866 return d
1867
1868 def _exec_super(self, codestr, optimized=False):
1869 # The compiler checks for statically visible shadowing of the name
1870 # `super`, and declines to emit `LOAD_SUPER_ATTR` if shadowing is found.
1871 # So inserting `super = super` prevents the compiler from emitting
1872 # `LOAD_SUPER_ATTR`, and allows us to test that monitoring events for
1873 # `LOAD_SUPER_ATTR` are equivalent to those we'd get from the
1874 # un-optimized `LOAD_GLOBAL super; CALL; LOAD_ATTR` form.
1875 assignment = "x = 1" if optimized else "super = super"
1876 codestr = f"{assignment}\n{textwrap.dedent(codestr)}"
1877 co = compile(codestr, "<string>", "exec")
1878 # validate that we really do have a LOAD_SUPER_ATTR, only when optimized
1879 self.assertEqual(self._has_load_super_attr(co), optimized)
1880 return self._exec(co)
1881
1882 def _has_load_super_attr(self, co):
1883 has = any(instr.opname == "LOAD_SUPER_ATTR" for instr in dis.get_instructions(co))

Callers 3

_super_method_callMethod · 0.95
_super_attrMethod · 0.95

Calls 5

_has_load_super_attrMethod · 0.95
_execMethod · 0.95
compileFunction · 0.50
dedentMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected