Skip to content

Commit c076d48

Browse files
bpo-42416: Use inspect.getdoc for IDLE calltips (GH-23416)
Inspect.getdoc(ob) sometimes gets docstrings when ob.__doc__ is None. (cherry picked from commit 7ddbaa7) Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
1 parent 5f463e5 commit c076d48

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

Lib/idlelib/NEWS.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ Released on 2020-12-??
33
======================================
44

55

6+
bpo-42416: Get docstrings for IDLE calltips more often
7+
by using inspect.getdoc.
8+
69
bpo-33987: Mostly finish using ttk widgets, mainly for editor,
710
settings, and searches. Some patches by Mark Roseman.
811

Lib/idlelib/calltip.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ def get_argspec(ob):
165165
ob_call = ob.__call__
166166
except BaseException: # Buggy user object could raise anything.
167167
return '' # No popup for non-callables.
168+
# For Get_argspecTest.test_buggy_getattr_class, CallA() & CallB().
168169
fob = ob_call if isinstance(ob_call, types.MethodType) else ob
169170

170171
# Initialize argspec and wrap it to get lines.
@@ -185,10 +186,7 @@ def get_argspec(ob):
185186
if len(argspec) > _MAX_COLS else [argspec] if argspec else [])
186187

187188
# Augment lines from docstring, if any, and join to get argspec.
188-
if isinstance(ob_call, types.MethodType):
189-
doc = ob_call.__doc__
190-
else:
191-
doc = getattr(ob, "__doc__", "")
189+
doc = inspect.getdoc(ob)
192190
if doc:
193191
for line in doc.split('\n', _MAX_LINES)[:_MAX_LINES]:
194192
line = line.strip()

Lib/idlelib/idle_test/test_calltip.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,12 @@ def test_signature_wrap(self):
9999
(width=70, initial_indent='', subsequent_indent='', expand_tabs=True,
100100
replace_whitespace=True, fix_sentence_endings=False, break_long_words=True,
101101
drop_whitespace=True, break_on_hyphens=True, tabsize=8, *, max_lines=None,
102-
placeholder=' [...]')''')
102+
placeholder=' [...]')
103+
Object for wrapping/filling text. The public interface consists of
104+
the wrap() and fill() methods; the other methods are just there for
105+
subclasses to override in order to tweak the default behaviour.
106+
If you want to completely replace the main wrapping algorithm,
107+
you\'ll probably have to override _wrap_chunks().''')
103108

104109
def test_properly_formated(self):
105110

@@ -241,7 +246,7 @@ class Type(type): # Type() requires 3 type args, returns class.
241246
__class__ = property({}.__getitem__, {}.__setitem__)
242247
class Object(metaclass=Type):
243248
__slots__ = '__class__'
244-
for meth, mtip in ((Type, default_tip), (Object, default_tip),
249+
for meth, mtip in ((Type, get_spec(type)), (Object, default_tip),
245250
(Object(), '')):
246251
with self.subTest(meth=meth, mtip=mtip):
247252
self.assertEqual(get_spec(meth), mtip)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Get docstrings for IDLE calltips more often by using inspect.getdoc.

0 commit comments

Comments
 (0)