https://github.com/python/cpython/commit/793cb77f55ac157cf3f32da863f39c408b29d78c commit: 793cb77f55ac157cf3f32da863f39c408b29d78c branch: 3.13 author: Miss Islington (bot) <[email protected]> committer: Yhg1s <[email protected]> date: 2024-09-29T18:21:57-07:00 summary:
[3.13] gh-123942: add missing test for docstring-handling code in ast_opt.c (GH-123943) (#123955) gh-123942: add missing test for docstring-handling code in ast_opt.c (GH-123943) (cherry picked from commit 6e23c89fcdd02b08fa6e9fa70d6e90763ddfc327) Co-authored-by: Irit Katriel <[email protected]> files: M Lib/test/test_compile.py diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py index b7e4d847822571..9c6bc31ff4922e 100644 --- a/Lib/test/test_compile.py +++ b/Lib/test/test_compile.py @@ -870,6 +870,32 @@ def unused_code_at_end(): 'RETURN_CONST', list(dis.get_instructions(unused_code_at_end))[-1].opname) + @support.cpython_only + def test_docstring(self): + src = textwrap.dedent(""" + def with_docstring(): + "docstring" + + def with_fstring(): + f"not docstring" + + def with_const_expression(): + "also" + " not docstring" + """) + + for opt in [0, 1, 2]: + with self.subTest(opt=opt): + code = compile(src, "<test>", "exec", optimize=opt) + ns = {} + exec(code, ns) + + if opt < 2: + self.assertEqual(ns['with_docstring'].__doc__, "docstring") + else: + self.assertIsNone(ns['with_docstring'].__doc__) + self.assertIsNone(ns['with_fstring'].__doc__) + self.assertIsNone(ns['with_const_expression'].__doc__) + @support.cpython_only def test_docstring_omitted(self): # See gh-115347 _______________________________________________ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: [email protected]
