gh-94318: Strip trailing spaces in pydoc text output (GH-94319)

This commit is contained in:
Serhiy Storchaka 2022-06-27 13:33:34 +03:00 committed by GitHub
parent f5c85aa3ee
commit 33fc3b5e42
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 78 additions and 78 deletions

View file

@ -1171,8 +1171,7 @@ class TextDoc(Doc):
def indent(self, text, prefix=' '): def indent(self, text, prefix=' '):
"""Indent text by prepending a given prefix to each line.""" """Indent text by prepending a given prefix to each line."""
if not text: return '' if not text: return ''
lines = [prefix + line for line in text.split('\n')] lines = [(prefix + line).rstrip() for line in text.split('\n')]
if lines: lines[-1] = lines[-1].rstrip()
return '\n'.join(lines) return '\n'.join(lines)
def section(self, title, contents): def section(self, title, contents):

View file

@ -4093,54 +4093,54 @@ Help on class Color in module %s:
class Color(enum.Enum) class Color(enum.Enum)
| Color(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None) | Color(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)
|\x20\x20 |
| Method resolution order: | Method resolution order:
| Color | Color
| enum.Enum | enum.Enum
| builtins.object | builtins.object
|\x20\x20 |
| Data and other attributes defined here: | Data and other attributes defined here:
|\x20\x20 |
| CYAN = <Color.CYAN: 1> | CYAN = <Color.CYAN: 1>
|\x20\x20 |
| MAGENTA = <Color.MAGENTA: 2> | MAGENTA = <Color.MAGENTA: 2>
|\x20\x20 |
| YELLOW = <Color.YELLOW: 3> | YELLOW = <Color.YELLOW: 3>
|\x20\x20 |
| ---------------------------------------------------------------------- | ----------------------------------------------------------------------
| Data descriptors inherited from enum.Enum: | Data descriptors inherited from enum.Enum:
|\x20\x20 |
| name | name
| The name of the Enum member. | The name of the Enum member.
|\x20\x20 |
| value | value
| The value of the Enum member. | The value of the Enum member.
|\x20\x20 |
| ---------------------------------------------------------------------- | ----------------------------------------------------------------------
| Methods inherited from enum.EnumType: | Methods inherited from enum.EnumType:
|\x20\x20 |
| __contains__(value) from enum.EnumType | __contains__(value) from enum.EnumType
| Return True if `value` is in `cls`. | Return True if `value` is in `cls`.
| |
| `value` is in `cls` if: | `value` is in `cls` if:
| 1) `value` is a member of `cls`, or | 1) `value` is a member of `cls`, or
| 2) `value` is the value of one of the `cls`'s members. | 2) `value` is the value of one of the `cls`'s members.
|\x20\x20 |
| __getitem__(name) from enum.EnumType | __getitem__(name) from enum.EnumType
| Return the member matching `name`. | Return the member matching `name`.
|\x20\x20 |
| __iter__() from enum.EnumType | __iter__() from enum.EnumType
| Return members in definition order. | Return members in definition order.
|\x20\x20 |
| __len__() from enum.EnumType | __len__() from enum.EnumType
| Return the number of members (no aliases) | Return the number of members (no aliases)
|\x20\x20 |
| ---------------------------------------------------------------------- | ----------------------------------------------------------------------
| Readonly properties inherited from enum.EnumType: | Readonly properties inherited from enum.EnumType:
|\x20\x20 |
| __members__ | __members__
| Returns a mapping of member name->value. | Returns a mapping of member name->value.
|\x20\x20\x20\x20\x20\x20 |
| This mapping lists all enum members, including aliases. Note that this | This mapping lists all enum members, including aliases. Note that this
| is a read-only view of the internal mapping.""" | is a read-only view of the internal mapping."""
@ -4149,30 +4149,30 @@ Help on class Color in module %s:
class Color(enum.Enum) class Color(enum.Enum)
| Color(value, names=None, *, module=None, qualname=None, type=None, start=1) | Color(value, names=None, *, module=None, qualname=None, type=None, start=1)
|\x20\x20 |
| Method resolution order: | Method resolution order:
| Color | Color
| enum.Enum | enum.Enum
| builtins.object | builtins.object
|\x20\x20 |
| Data and other attributes defined here: | Data and other attributes defined here:
|\x20\x20 |
| YELLOW = <Color.YELLOW: 3> | YELLOW = <Color.YELLOW: 3>
|\x20\x20 |
| MAGENTA = <Color.MAGENTA: 2> | MAGENTA = <Color.MAGENTA: 2>
|\x20\x20 |
| CYAN = <Color.CYAN: 1> | CYAN = <Color.CYAN: 1>
|\x20\x20 |
| ---------------------------------------------------------------------- | ----------------------------------------------------------------------
| Data descriptors inherited from enum.Enum: | Data descriptors inherited from enum.Enum:
|\x20\x20 |
| name | name
|\x20\x20 |
| value | value
|\x20\x20 |
| ---------------------------------------------------------------------- | ----------------------------------------------------------------------
| Data descriptors inherited from enum.EnumType: | Data descriptors inherited from enum.EnumType:
|\x20\x20 |
| __members__""" | __members__"""
class TestStdLib(unittest.TestCase): class TestStdLib(unittest.TestCase):

View file

@ -54,58 +54,58 @@ CLASSES
A A
B B
C C
\x20\x20\x20\x20
class A(builtins.object) class A(builtins.object)
| Hello and goodbye | Hello and goodbye
|\x20\x20 |
| Methods defined here: | Methods defined here:
|\x20\x20 |
| __init__() | __init__()
| Wow, I have no function! | Wow, I have no function!
|\x20\x20 |
| ---------------------------------------------------------------------- | ----------------------------------------------------------------------
| Data descriptors defined here: | Data descriptors defined here:
|\x20\x20 |
| __dict__%s | __dict__%s
|\x20\x20 |
| __weakref__%s | __weakref__%s
\x20\x20\x20\x20
class B(builtins.object) class B(builtins.object)
| Data descriptors defined here: | Data descriptors defined here:
|\x20\x20 |
| __dict__%s | __dict__%s
|\x20\x20 |
| __weakref__%s | __weakref__%s
|\x20\x20 |
| ---------------------------------------------------------------------- | ----------------------------------------------------------------------
| Data and other attributes defined here: | Data and other attributes defined here:
|\x20\x20 |
| NO_MEANING = 'eggs' | NO_MEANING = 'eggs'
|\x20\x20 |
| __annotations__ = {'NO_MEANING': <class 'str'>} | __annotations__ = {'NO_MEANING': <class 'str'>}
\x20\x20\x20\x20
class C(builtins.object) class C(builtins.object)
| Methods defined here: | Methods defined here:
|\x20\x20 |
| get_answer(self) | get_answer(self)
| Return say_no() | Return say_no()
|\x20\x20 |
| is_it_true(self) | is_it_true(self)
| Return self.get_answer() | Return self.get_answer()
|\x20\x20 |
| say_no(self) | say_no(self)
|\x20\x20 |
| ---------------------------------------------------------------------- | ----------------------------------------------------------------------
| Class methods defined here: | Class methods defined here:
|\x20\x20 |
| __class_getitem__(item) from builtins.type | __class_getitem__(item) from builtins.type
|\x20\x20 |
| ---------------------------------------------------------------------- | ----------------------------------------------------------------------
| Data descriptors defined here: | Data descriptors defined here:
|\x20\x20 |
| __dict__ | __dict__
| dictionary for instance variables (if defined) | dictionary for instance variables (if defined)
|\x20\x20 |
| __weakref__ | __weakref__
| list of weak references to the object (if defined) | list of weak references to the object (if defined)
@ -115,7 +115,7 @@ FUNCTIONS
hunger hunger
lack of Python lack of Python
war war
\x20\x20\x20\x20
nodoc_func() nodoc_func()
DATA DATA
@ -235,16 +235,16 @@ Help on class DA in module %s:
class DA(builtins.object) class DA(builtins.object)
| Data descriptors defined here: | Data descriptors defined here:
|\x20\x20 |
| __dict__%s | __dict__%s
|\x20\x20 |
| __weakref__%s | __weakref__%s
|\x20\x20 |
| ham | ham
|\x20\x20 |
| ---------------------------------------------------------------------- | ----------------------------------------------------------------------
| Data and other attributes inherited from Meta: | Data and other attributes inherited from Meta:
|\x20\x20 |
| ham = 'spam' | ham = 'spam'
""".strip() """.strip()
@ -253,7 +253,7 @@ Help on class Class in module %s:
class Class(builtins.object) class Class(builtins.object)
| Data and other attributes inherited from Meta: | Data and other attributes inherited from Meta:
|\x20\x20 |
| LIFE = 42 | LIFE = 42
""".strip() """.strip()
@ -262,7 +262,7 @@ Help on class Class1 in module %s:
class Class1(builtins.object) class Class1(builtins.object)
| Data and other attributes inherited from Meta1: | Data and other attributes inherited from Meta1:
|\x20\x20 |
| one = 1 | one = 1
""".strip() """.strip()
@ -274,19 +274,19 @@ class Class2(Class1)
| Class2 | Class2
| Class1 | Class1
| builtins.object | builtins.object
|\x20\x20 |
| Data and other attributes inherited from Meta1: | Data and other attributes inherited from Meta1:
|\x20\x20 |
| one = 1 | one = 1
|\x20\x20 |
| ---------------------------------------------------------------------- | ----------------------------------------------------------------------
| Data and other attributes inherited from Meta3: | Data and other attributes inherited from Meta3:
|\x20\x20 |
| three = 3 | three = 3
|\x20\x20 |
| ---------------------------------------------------------------------- | ----------------------------------------------------------------------
| Data and other attributes inherited from Meta2: | Data and other attributes inherited from Meta2:
|\x20\x20 |
| two = 2 | two = 2
""".strip() """.strip()
@ -295,7 +295,7 @@ Help on class C in module %s:
class C(builtins.object) class C(builtins.object)
| Data and other attributes defined here: | Data and other attributes defined here:
|\x20\x20 |
| here = 'present!' | here = 'present!'
""".strip() """.strip()
@ -785,33 +785,33 @@ class B(A)
| B | B
| A | A
| builtins.object | builtins.object
|\x20\x20 |
| Methods defined here: | Methods defined here:
|\x20\x20 |
| b_size = a_size(self) | b_size = a_size(self)
|\x20\x20 |
| itemconfig = itemconfigure(self, tagOrId, cnf=None, **kw) | itemconfig = itemconfigure(self, tagOrId, cnf=None, **kw)
|\x20\x20 |
| itemconfigure(self, tagOrId, cnf=None, **kw) | itemconfigure(self, tagOrId, cnf=None, **kw)
| Configure resources of an item TAGORID. | Configure resources of an item TAGORID.
|\x20\x20 |
| ---------------------------------------------------------------------- | ----------------------------------------------------------------------
| Methods inherited from A: | Methods inherited from A:
|\x20\x20 |
| a_size(self) | a_size(self)
| Return size | Return size
|\x20\x20 |
| lift = tkraise(self, aboveThis=None) | lift = tkraise(self, aboveThis=None)
|\x20\x20 |
| tkraise(self, aboveThis=None) | tkraise(self, aboveThis=None)
| Raise this widget in the stacking order. | Raise this widget in the stacking order.
|\x20\x20 |
| ---------------------------------------------------------------------- | ----------------------------------------------------------------------
| Data descriptors inherited from A: | Data descriptors inherited from A:
|\x20\x20 |
| __dict__ | __dict__
| dictionary for instance variables (if defined) | dictionary for instance variables (if defined)
|\x20\x20 |
| __weakref__ | __weakref__
| list of weak references to the object (if defined) | list of weak references to the object (if defined)
''' % __name__) ''' % __name__)
@ -1180,7 +1180,7 @@ sm(x, y)
""") """)
self.assertIn(""" self.assertIn("""
| Static methods defined here: | Static methods defined here:
|\x20\x20 |
| sm(x, y) | sm(x, y)
| A static method | A static method
""", pydoc.plain(pydoc.render_doc(X))) """, pydoc.plain(pydoc.render_doc(X)))
@ -1201,7 +1201,7 @@ cm(x) method of builtins.type instance
""") """)
self.assertIn(""" self.assertIn("""
| Class methods defined here: | Class methods defined here:
|\x20\x20 |
| cm(x) from builtins.type | cm(x) from builtins.type
| A class method | A class method
""", pydoc.plain(pydoc.render_doc(X))) """, pydoc.plain(pydoc.render_doc(X)))

View file

@ -0,0 +1 @@
Strip trailing spaces in :mod:`pydoc` text output.