mirror of
https://github.com/python/cpython.git
synced 2025-09-27 10:50:04 +00:00
gh-81283: compiler: remove indent from docstring (#106411)
Co-authored-by: Éric <merwok@netwok.org>
This commit is contained in:
parent
bbf6297985
commit
2566b74b26
9 changed files with 246 additions and 30 deletions
|
@ -596,9 +596,40 @@ class TestRetrievingSourceCode(GetSourceBase):
|
|||
self.assertEqual(finddoc(int.from_bytes), int.from_bytes.__doc__)
|
||||
self.assertEqual(finddoc(int.real), int.real.__doc__)
|
||||
|
||||
cleandoc_testdata = [
|
||||
# first line should have different margin
|
||||
(' An\n indented\n docstring.', 'An\nindented\n docstring.'),
|
||||
# trailing whitespace are not removed.
|
||||
(' An \n \n indented \n docstring. ',
|
||||
'An \n \nindented \n docstring. '),
|
||||
# NUL is not termination.
|
||||
('doc\0string\n\n second\0line\n third\0line\0',
|
||||
'doc\0string\n\nsecond\0line\nthird\0line\0'),
|
||||
# first line is lstrip()-ped. other lines are kept when no margin.[w:
|
||||
(' ', ''),
|
||||
# compiler.cleandoc() doesn't strip leading/trailing newlines
|
||||
# to keep maximum backward compatibility.
|
||||
# inspect.cleandoc() removes them.
|
||||
('\n\n\n first paragraph\n\n second paragraph\n\n',
|
||||
'\n\n\nfirst paragraph\n\n second paragraph\n\n'),
|
||||
(' \n \n \n ', '\n \n \n '),
|
||||
]
|
||||
|
||||
def test_cleandoc(self):
|
||||
self.assertEqual(inspect.cleandoc('An\n indented\n docstring.'),
|
||||
'An\nindented\ndocstring.')
|
||||
func = inspect.cleandoc
|
||||
for i, (input, expected) in enumerate(self.cleandoc_testdata):
|
||||
# only inspect.cleandoc() strip \n
|
||||
expected = expected.strip('\n')
|
||||
with self.subTest(i=i):
|
||||
self.assertEqual(func(input), expected)
|
||||
|
||||
@cpython_only
|
||||
def test_c_cleandoc(self):
|
||||
import _testinternalcapi
|
||||
func = _testinternalcapi.compiler_cleandoc
|
||||
for i, (input, expected) in enumerate(self.cleandoc_testdata):
|
||||
with self.subTest(i=i):
|
||||
self.assertEqual(func(input), expected)
|
||||
|
||||
def test_getcomments(self):
|
||||
self.assertEqual(inspect.getcomments(mod), '# line 1\n')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue