Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add docstring test under -OO
  • Loading branch information
xuantengh committed Nov 8, 2024
commit fe1db96db3b773a5f966f45a6d1f75c7ff4bcdcc
27 changes: 27 additions & 0 deletions Lib/test/test_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,33 @@ def f():
3 * [(42, 42, None, None)],
)

@cpython_only
def test_docstring_under_o2(self):
code = textwrap.dedent('''
def has_docstring(x, y):
"""This is a first-line doc string"""
"""This is a second-line doc string"""
a = x + y
b = x - y
return a, b


def no_docstring(x):
def g(y):
return x + y
return g


async def async_func():
"""asynf function doc string"""
pass


for func in [has_docstring, no_docstring(4), async_func]:
assert(func.__doc__ is None)
''')

rc, out, err = assert_python_ok('-OO', '-c', code)

if check_impl_detail(cpython=True) and ctypes is not None:
py = ctypes.pythonapi
Expand Down