(self, codestr, optimized=False)
| 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)) |
no test coverage detected