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

Method test_docstring_omitted

Lib/test/test_compile.py:973–995  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 6

getvalueMethod · 0.95
disMethod · 0.80
assertNotInMethod · 0.80
compileFunction · 0.50
dedentMethod · 0.45
subTestMethod · 0.45

Tested by

no test coverage detected