| 971 | |
| 972 | @support.cpython_only |
| 973 | def test_docstring_omitted(self): |
| 974 | # See gh-115347 |
| 975 | src = textwrap.dedent(""" |
| 976 | def f(): |
| 977 | "docstring1" |
| 978 | def h(): |
| 979 | "docstring2" |
| 980 | return 42 |
| 981 | |
| 982 | class C: |
| 983 | "docstring3" |
| 984 | pass |
| 985 | |
| 986 | return h |
| 987 | """) |
| 988 | for opt in [-1, 0, 1, 2]: |
| 989 | for mode in ["exec", "single"]: |
| 990 | with self.subTest(opt=opt, mode=mode): |
| 991 | code = compile(src, "<test>", mode, optimize=opt) |
| 992 | output = io.StringIO() |
| 993 | with contextlib.redirect_stdout(output): |
| 994 | dis.dis(code) |
| 995 | self.assertNotIn('NOP', output.getvalue()) |
| 996 | |
| 997 | def test_dont_merge_constants(self): |
| 998 | # Issue #25843: compile() must not merge constants which are equal |