[Python-checkins] gh-94318: Strip trailing spaces in pydoc text output (GH-94319)

serhiy-storchaka webhook-mailer at python.org
Mon Jun 27 06:33:58 EDT 2022


https://github.com/python/cpython/commit/33fc3b5e42f241ab81cc6d115711545b4f9e271e
commit: 33fc3b5e42f241ab81cc6d115711545b4f9e271e
branch: main
author: Serhiy Storchaka <storchaka at gmail.com>
committer: serhiy-storchaka <storchaka at gmail.com>
date: 2022年06月27日T13:33:34+03:00
summary:
gh-94318: Strip trailing spaces in pydoc text output (GH-94319)
files:
A Misc/NEWS.d/next/Library/2022-06-27-10-33-18.gh-issue-94318.jR4_QV.rst
M Lib/pydoc.py
M Lib/test/test_enum.py
M Lib/test/test_pydoc.py
diff --git a/Lib/pydoc.py b/Lib/pydoc.py
index e96cacbe43445..a4dc910c8a8e8 100755
--- a/Lib/pydoc.py
+++ b/Lib/pydoc.py
@@ -1171,8 +1171,7 @@ def bold(self, text):
 def indent(self, text, prefix=' '):
 """Indent text by prepending a given prefix to each line."""
 if not text: return ''
- lines = [prefix + line for line in text.split('\n')]
- if lines: lines[-1] = lines[-1].rstrip()
+ lines = [(prefix + line).rstrip() for line in text.split('\n')]
 return '\n'.join(lines)
 
 def section(self, title, contents):
diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py
index 93b7a52bec280..a26350992cf9d 100644
--- a/Lib/test/test_enum.py
+++ b/Lib/test/test_enum.py
@@ -4093,54 +4093,54 @@ class TestEnumTypeSubclassing(unittest.TestCase):
 
 class Color(enum.Enum)
 | Color(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)
- |\x20\x20
+ |
 | Method resolution order:
 | Color
 | enum.Enum
 | builtins.object
- |\x20\x20
+ |
 | Data and other attributes defined here:
- |\x20\x20
+ |
 | CYAN = <Color.CYAN: 1>
- |\x20\x20
+ |
 | MAGENTA = <Color.MAGENTA: 2>
- |\x20\x20
+ |
 | YELLOW = <Color.YELLOW: 3>
- |\x20\x20
+ |
 | ----------------------------------------------------------------------
 | Data descriptors inherited from enum.Enum:
- |\x20\x20
+ |
 | name
 | The name of the Enum member.
- |\x20\x20
+ |
 | value
 | The value of the Enum member.
- |\x20\x20
+ |
 | ----------------------------------------------------------------------
 | Methods inherited from enum.EnumType:
- |\x20\x20
+ |
 | __contains__(value) from enum.EnumType
 | Return True if `value` is in `cls`.
- | 
+ |
 | `value` is in `cls` if:
 | 1) `value` is a member of `cls`, or
 | 2) `value` is the value of one of the `cls`'s members.
- |\x20\x20
+ |
 | __getitem__(name) from enum.EnumType
 | Return the member matching `name`.
- |\x20\x20
+ |
 | __iter__() from enum.EnumType
 | Return members in definition order.
- |\x20\x20
+ |
 | __len__() from enum.EnumType
 | Return the number of members (no aliases)
- |\x20\x20
+ |
 | ----------------------------------------------------------------------
 | Readonly properties inherited from enum.EnumType:
- |\x20\x20
+ |
 | __members__
 | Returns a mapping of member name->value.
- |\x20\x20\x20\x20\x20\x20
+ |
 | This mapping lists all enum members, including aliases. Note that this
 | is a read-only view of the internal mapping."""
 
@@ -4149,30 +4149,30 @@ class Color(enum.Enum)
 
 class Color(enum.Enum)
 | Color(value, names=None, *, module=None, qualname=None, type=None, start=1)
- |\x20\x20
+ |
 | Method resolution order:
 | Color
 | enum.Enum
 | builtins.object
- |\x20\x20
+ |
 | Data and other attributes defined here:
- |\x20\x20
+ |
 | YELLOW = <Color.YELLOW: 3>
- |\x20\x20
+ |
 | MAGENTA = <Color.MAGENTA: 2>
- |\x20\x20
+ |
 | CYAN = <Color.CYAN: 1>
- |\x20\x20
+ |
 | ----------------------------------------------------------------------
 | Data descriptors inherited from enum.Enum:
- |\x20\x20
+ |
 | name
- |\x20\x20
+ |
 | value
- |\x20\x20
+ |
 | ----------------------------------------------------------------------
 | Data descriptors inherited from enum.EnumType:
- |\x20\x20
+ |
 | __members__"""
 
 class TestStdLib(unittest.TestCase):
diff --git a/Lib/test/test_pydoc.py b/Lib/test/test_pydoc.py
index 89faf0d9141f9..8ab3289dd7400 100644
--- a/Lib/test/test_pydoc.py
+++ b/Lib/test/test_pydoc.py
@@ -54,58 +54,58 @@ class nonascii:
 A
 B
 C
-\x20\x20\x20\x20
+
 class A(builtins.object)
 | Hello and goodbye
- |\x20\x20
+ |
 | Methods defined here:
- |\x20\x20
+ |
 | __init__()
 | Wow, I have no function!
- |\x20\x20
+ |
 | ----------------------------------------------------------------------
 | Data descriptors defined here:
- |\x20\x20
+ |
 | __dict__%s
- |\x20\x20
+ |
 | __weakref__%s
-\x20\x20\x20\x20
+
 class B(builtins.object)
 | Data descriptors defined here:
- |\x20\x20
+ |
 | __dict__%s
- |\x20\x20
+ |
 | __weakref__%s
- |\x20\x20
+ |
 | ----------------------------------------------------------------------
 | Data and other attributes defined here:
- |\x20\x20
+ |
 | NO_MEANING = 'eggs'
- |\x20\x20
+ |
 | __annotations__ = {'NO_MEANING': <class 'str'>}
-\x20\x20\x20\x20
+
 class C(builtins.object)
 | Methods defined here:
- |\x20\x20
+ |
 | get_answer(self)
 | Return say_no()
- |\x20\x20
+ |
 | is_it_true(self)
 | Return self.get_answer()
- |\x20\x20
+ |
 | say_no(self)
- |\x20\x20
+ |
 | ----------------------------------------------------------------------
 | Class methods defined here:
- |\x20\x20
+ |
 | __class_getitem__(item) from builtins.type
- |\x20\x20
+ |
 | ----------------------------------------------------------------------
 | Data descriptors defined here:
- |\x20\x20
+ |
 | __dict__
 | dictionary for instance variables (if defined)
- |\x20\x20
+ |
 | __weakref__
 | list of weak references to the object (if defined)
 
@@ -115,7 +115,7 @@ class C(builtins.object)
 hunger
 lack of Python
 war
-\x20\x20\x20\x20
+
 nodoc_func()
 
 DATA
@@ -235,16 +235,16 @@ class C(builtins.object)
 
 class DA(builtins.object)
 | Data descriptors defined here:
- |\x20\x20
+ |
 | __dict__%s
- |\x20\x20
+ |
 | __weakref__%s
- |\x20\x20
+ |
 | ham
- |\x20\x20
+ |
 | ----------------------------------------------------------------------
 | Data and other attributes inherited from Meta:
- |\x20\x20
+ |
 | ham = 'spam'
 """.strip()
 
@@ -253,7 +253,7 @@ class DA(builtins.object)
 
 class Class(builtins.object)
 | Data and other attributes inherited from Meta:
- |\x20\x20
+ |
 | LIFE = 42
 """.strip()
 
@@ -262,7 +262,7 @@ class Class(builtins.object)
 
 class Class1(builtins.object)
 | Data and other attributes inherited from Meta1:
- |\x20\x20
+ |
 | one = 1
 """.strip()
 
@@ -274,19 +274,19 @@ class Class2(Class1)
 | Class2
 | Class1
 | builtins.object
- |\x20\x20
+ |
 | Data and other attributes inherited from Meta1:
- |\x20\x20
+ |
 | one = 1
- |\x20\x20
+ |
 | ----------------------------------------------------------------------
 | Data and other attributes inherited from Meta3:
- |\x20\x20
+ |
 | three = 3
- |\x20\x20
+ |
 | ----------------------------------------------------------------------
 | Data and other attributes inherited from Meta2:
- |\x20\x20
+ |
 | two = 2
 """.strip()
 
@@ -295,7 +295,7 @@ class Class2(Class1)
 
 class C(builtins.object)
 | Data and other attributes defined here:
- |\x20\x20
+ |
 | here = 'present!'
 """.strip()
 
@@ -785,33 +785,33 @@ class B(A)
 | B
 | A
 | builtins.object
- |\x20\x20
+ |
 | Methods defined here:
- |\x20\x20
+ |
 | b_size = a_size(self)
- |\x20\x20
+ |
 | itemconfig = itemconfigure(self, tagOrId, cnf=None, **kw)
- |\x20\x20
+ |
 | itemconfigure(self, tagOrId, cnf=None, **kw)
 | Configure resources of an item TAGORID.
- |\x20\x20
+ |
 | ----------------------------------------------------------------------
 | Methods inherited from A:
- |\x20\x20
+ |
 | a_size(self)
 | Return size
- |\x20\x20
+ |
 | lift = tkraise(self, aboveThis=None)
- |\x20\x20
+ |
 | tkraise(self, aboveThis=None)
 | Raise this widget in the stacking order.
- |\x20\x20
+ |
 | ----------------------------------------------------------------------
 | Data descriptors inherited from A:
- |\x20\x20
+ |
 | __dict__
 | dictionary for instance variables (if defined)
- |\x20\x20
+ |
 | __weakref__
 | list of weak references to the object (if defined)
 ''' % __name__)
@@ -1180,7 +1180,7 @@ def sm(x, y):
 """)
 self.assertIn("""
 | Static methods defined here:
- |\x20\x20
+ |
 | sm(x, y)
 | A static method
 """, pydoc.plain(pydoc.render_doc(X)))
@@ -1201,7 +1201,7 @@ def cm(cls, x):
 """)
 self.assertIn("""
 | Class methods defined here:
- |\x20\x20
+ |
 | cm(x) from builtins.type
 | A class method
 """, pydoc.plain(pydoc.render_doc(X)))
diff --git a/Misc/NEWS.d/next/Library/2022-06-27-10-33-18.gh-issue-94318.jR4_QV.rst b/Misc/NEWS.d/next/Library/2022-06-27-10-33-18.gh-issue-94318.jR4_QV.rst
new file mode 100644
index 0000000000000..97a7cd8c9e7a5
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2022-06-27-10-33-18.gh-issue-94318.jR4_QV.rst
@@ -0,0 +1 @@
+Strip trailing spaces in :mod:`pydoc` text output.


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /