Skip to content

Commit 33fc3b5

Browse files
gh-94318: Strip trailing spaces in pydoc text output (GH-94319)
1 parent f5c85aa commit 33fc3b5

File tree

4 files changed

+78
-78
lines changed

4 files changed

+78
-78
lines changed

Lib/pydoc.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,8 +1171,7 @@ def bold(self, text):
11711171
def indent(self, text, prefix=' '):
11721172
"""Indent text by prepending a given prefix to each line."""
11731173
if not text: return ''
1174-
lines = [prefix + line for line in text.split('\n')]
1175-
if lines: lines[-1] = lines[-1].rstrip()
1174+
lines = [(prefix + line).rstrip() for line in text.split('\n')]
11761175
return '\n'.join(lines)
11771176

11781177
def section(self, title, contents):

Lib/test/test_enum.py

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4093,54 +4093,54 @@ class TestEnumTypeSubclassing(unittest.TestCase):
40934093
40944094
class Color(enum.Enum)
40954095
| Color(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)
4096-
|\x20\x20
4096+
|
40974097
| Method resolution order:
40984098
| Color
40994099
| enum.Enum
41004100
| builtins.object
4101-
|\x20\x20
4101+
|
41024102
| Data and other attributes defined here:
4103-
|\x20\x20
4103+
|
41044104
| CYAN = <Color.CYAN: 1>
4105-
|\x20\x20
4105+
|
41064106
| MAGENTA = <Color.MAGENTA: 2>
4107-
|\x20\x20
4107+
|
41084108
| YELLOW = <Color.YELLOW: 3>
4109-
|\x20\x20
4109+
|
41104110
| ----------------------------------------------------------------------
41114111
| Data descriptors inherited from enum.Enum:
4112-
|\x20\x20
4112+
|
41134113
| name
41144114
| The name of the Enum member.
4115-
|\x20\x20
4115+
|
41164116
| value
41174117
| The value of the Enum member.
4118-
|\x20\x20
4118+
|
41194119
| ----------------------------------------------------------------------
41204120
| Methods inherited from enum.EnumType:
4121-
|\x20\x20
4121+
|
41224122
| __contains__(value) from enum.EnumType
41234123
| Return True if `value` is in `cls`.
4124-
|
4124+
|
41254125
| `value` is in `cls` if:
41264126
| 1) `value` is a member of `cls`, or
41274127
| 2) `value` is the value of one of the `cls`'s members.
4128-
|\x20\x20
4128+
|
41294129
| __getitem__(name) from enum.EnumType
41304130
| Return the member matching `name`.
4131-
|\x20\x20
4131+
|
41324132
| __iter__() from enum.EnumType
41334133
| Return members in definition order.
4134-
|\x20\x20
4134+
|
41354135
| __len__() from enum.EnumType
41364136
| Return the number of members (no aliases)
4137-
|\x20\x20
4137+
|
41384138
| ----------------------------------------------------------------------
41394139
| Readonly properties inherited from enum.EnumType:
4140-
|\x20\x20
4140+
|
41414141
| __members__
41424142
| Returns a mapping of member name->value.
4143-
|\x20\x20\x20\x20\x20\x20
4143+
|
41444144
| This mapping lists all enum members, including aliases. Note that this
41454145
| is a read-only view of the internal mapping."""
41464146

@@ -4149,30 +4149,30 @@ class Color(enum.Enum)
41494149
41504150
class Color(enum.Enum)
41514151
| Color(value, names=None, *, module=None, qualname=None, type=None, start=1)
4152-
|\x20\x20
4152+
|
41534153
| Method resolution order:
41544154
| Color
41554155
| enum.Enum
41564156
| builtins.object
4157-
|\x20\x20
4157+
|
41584158
| Data and other attributes defined here:
4159-
|\x20\x20
4159+
|
41604160
| YELLOW = <Color.YELLOW: 3>
4161-
|\x20\x20
4161+
|
41624162
| MAGENTA = <Color.MAGENTA: 2>
4163-
|\x20\x20
4163+
|
41644164
| CYAN = <Color.CYAN: 1>
4165-
|\x20\x20
4165+
|
41664166
| ----------------------------------------------------------------------
41674167
| Data descriptors inherited from enum.Enum:
4168-
|\x20\x20
4168+
|
41694169
| name
4170-
|\x20\x20
4170+
|
41714171
| value
4172-
|\x20\x20
4172+
|
41734173
| ----------------------------------------------------------------------
41744174
| Data descriptors inherited from enum.EnumType:
4175-
|\x20\x20
4175+
|
41764176
| __members__"""
41774177

41784178
class TestStdLib(unittest.TestCase):

Lib/test/test_pydoc.py

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -54,58 +54,58 @@ class nonascii:
5454
A
5555
B
5656
C
57-
\x20\x20\x20\x20
57+
5858
class A(builtins.object)
5959
| Hello and goodbye
60-
|\x20\x20
60+
|
6161
| Methods defined here:
62-
|\x20\x20
62+
|
6363
| __init__()
6464
| Wow, I have no function!
65-
|\x20\x20
65+
|
6666
| ----------------------------------------------------------------------
6767
| Data descriptors defined here:
68-
|\x20\x20
68+
|
6969
| __dict__%s
70-
|\x20\x20
70+
|
7171
| __weakref__%s
72-
\x20\x20\x20\x20
72+
7373
class B(builtins.object)
7474
| Data descriptors defined here:
75-
|\x20\x20
75+
|
7676
| __dict__%s
77-
|\x20\x20
77+
|
7878
| __weakref__%s
79-
|\x20\x20
79+
|
8080
| ----------------------------------------------------------------------
8181
| Data and other attributes defined here:
82-
|\x20\x20
82+
|
8383
| NO_MEANING = 'eggs'
84-
|\x20\x20
84+
|
8585
| __annotations__ = {'NO_MEANING': <class 'str'>}
86-
\x20\x20\x20\x20
86+
8787
class C(builtins.object)
8888
| Methods defined here:
89-
|\x20\x20
89+
|
9090
| get_answer(self)
9191
| Return say_no()
92-
|\x20\x20
92+
|
9393
| is_it_true(self)
9494
| Return self.get_answer()
95-
|\x20\x20
95+
|
9696
| say_no(self)
97-
|\x20\x20
97+
|
9898
| ----------------------------------------------------------------------
9999
| Class methods defined here:
100-
|\x20\x20
100+
|
101101
| __class_getitem__(item) from builtins.type
102-
|\x20\x20
102+
|
103103
| ----------------------------------------------------------------------
104104
| Data descriptors defined here:
105-
|\x20\x20
105+
|
106106
| __dict__
107107
| dictionary for instance variables (if defined)
108-
|\x20\x20
108+
|
109109
| __weakref__
110110
| list of weak references to the object (if defined)
111111
@@ -115,7 +115,7 @@ class C(builtins.object)
115115
hunger
116116
lack of Python
117117
war
118-
\x20\x20\x20\x20
118+
119119
nodoc_func()
120120
121121
DATA
@@ -235,16 +235,16 @@ class C(builtins.object)
235235
236236
class DA(builtins.object)
237237
| Data descriptors defined here:
238-
|\x20\x20
238+
|
239239
| __dict__%s
240-
|\x20\x20
240+
|
241241
| __weakref__%s
242-
|\x20\x20
242+
|
243243
| ham
244-
|\x20\x20
244+
|
245245
| ----------------------------------------------------------------------
246246
| Data and other attributes inherited from Meta:
247-
|\x20\x20
247+
|
248248
| ham = 'spam'
249249
""".strip()
250250

@@ -253,7 +253,7 @@ class DA(builtins.object)
253253
254254
class Class(builtins.object)
255255
| Data and other attributes inherited from Meta:
256-
|\x20\x20
256+
|
257257
| LIFE = 42
258258
""".strip()
259259

@@ -262,7 +262,7 @@ class Class(builtins.object)
262262
263263
class Class1(builtins.object)
264264
| Data and other attributes inherited from Meta1:
265-
|\x20\x20
265+
|
266266
| one = 1
267267
""".strip()
268268

@@ -274,19 +274,19 @@ class Class2(Class1)
274274
| Class2
275275
| Class1
276276
| builtins.object
277-
|\x20\x20
277+
|
278278
| Data and other attributes inherited from Meta1:
279-
|\x20\x20
279+
|
280280
| one = 1
281-
|\x20\x20
281+
|
282282
| ----------------------------------------------------------------------
283283
| Data and other attributes inherited from Meta3:
284-
|\x20\x20
284+
|
285285
| three = 3
286-
|\x20\x20
286+
|
287287
| ----------------------------------------------------------------------
288288
| Data and other attributes inherited from Meta2:
289-
|\x20\x20
289+
|
290290
| two = 2
291291
""".strip()
292292

@@ -295,7 +295,7 @@ class Class2(Class1)
295295
296296
class C(builtins.object)
297297
| Data and other attributes defined here:
298-
|\x20\x20
298+
|
299299
| here = 'present!'
300300
""".strip()
301301

@@ -785,33 +785,33 @@ class B(A)
785785
| B
786786
| A
787787
| builtins.object
788-
|\x20\x20
788+
|
789789
| Methods defined here:
790-
|\x20\x20
790+
|
791791
| b_size = a_size(self)
792-
|\x20\x20
792+
|
793793
| itemconfig = itemconfigure(self, tagOrId, cnf=None, **kw)
794-
|\x20\x20
794+
|
795795
| itemconfigure(self, tagOrId, cnf=None, **kw)
796796
| Configure resources of an item TAGORID.
797-
|\x20\x20
797+
|
798798
| ----------------------------------------------------------------------
799799
| Methods inherited from A:
800-
|\x20\x20
800+
|
801801
| a_size(self)
802802
| Return size
803-
|\x20\x20
803+
|
804804
| lift = tkraise(self, aboveThis=None)
805-
|\x20\x20
805+
|
806806
| tkraise(self, aboveThis=None)
807807
| Raise this widget in the stacking order.
808-
|\x20\x20
808+
|
809809
| ----------------------------------------------------------------------
810810
| Data descriptors inherited from A:
811-
|\x20\x20
811+
|
812812
| __dict__
813813
| dictionary for instance variables (if defined)
814-
|\x20\x20
814+
|
815815
| __weakref__
816816
| list of weak references to the object (if defined)
817817
''' % __name__)
@@ -1180,7 +1180,7 @@ def sm(x, y):
11801180
""")
11811181
self.assertIn("""
11821182
| Static methods defined here:
1183-
|\x20\x20
1183+
|
11841184
| sm(x, y)
11851185
| A static method
11861186
""", pydoc.plain(pydoc.render_doc(X)))
@@ -1201,7 +1201,7 @@ def cm(cls, x):
12011201
""")
12021202
self.assertIn("""
12031203
| Class methods defined here:
1204-
|\x20\x20
1204+
|
12051205
| cm(x) from builtins.type
12061206
| A class method
12071207
""", pydoc.plain(pydoc.render_doc(X)))
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Strip trailing spaces in :mod:`pydoc` text output.

0 commit comments

Comments
 (0)