mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
gh-126072: Set docstring attribute for module and class (#126231)
This commit is contained in:
parent
b19d12f447
commit
6ec886531f
6 changed files with 77 additions and 20 deletions
|
@ -178,6 +178,20 @@ freevars: ()
|
|||
nlocals: 3
|
||||
flags: 3
|
||||
consts: ("'hello'", "'world'")
|
||||
|
||||
>>> class class_with_docstring:
|
||||
... '''This is a docstring for class'''
|
||||
... '''This line is not docstring'''
|
||||
... pass
|
||||
|
||||
>>> print(class_with_docstring.__doc__)
|
||||
This is a docstring for class
|
||||
|
||||
>>> class class_without_docstring:
|
||||
... pass
|
||||
|
||||
>>> print(class_without_docstring.__doc__)
|
||||
None
|
||||
"""
|
||||
|
||||
import copy
|
||||
|
@ -854,6 +868,33 @@ class CodeLocationTest(unittest.TestCase):
|
|||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue