Skip to content

[3.9] bpo-42416: Use inspect.getdoc for IDLE calltips (GH-23416) #23417

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Lib/idlelib/NEWS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ Released on 2020-12-07?
======================================


bpo-42416: Get docstrings for IDLE calltips more often
by using inspect.getdoc.

bpo-33987: Mostly finish using ttk widgets, mainly for editor,
settings, and searches. Some patches by Mark Roseman.

Expand Down
6 changes: 2 additions & 4 deletions Lib/idlelib/calltip.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ def get_argspec(ob):
ob_call = ob.__call__
except BaseException: # Buggy user object could raise anything.
return '' # No popup for non-callables.
# For Get_argspecTest.test_buggy_getattr_class, CallA() & CallB().
fob = ob_call if isinstance(ob_call, types.MethodType) else ob

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

# Augment lines from docstring, if any, and join to get argspec.
if isinstance(ob_call, types.MethodType):
doc = ob_call.__doc__
else:
doc = getattr(ob, "__doc__", "")
doc = inspect.getdoc(ob)
if doc:
for line in doc.split('\n', _MAX_LINES)[:_MAX_LINES]:
line = line.strip()
Expand Down
9 changes: 7 additions & 2 deletions Lib/idlelib/idle_test/test_calltip.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,12 @@ def test_signature_wrap(self):
(width=70, initial_indent='', subsequent_indent='', expand_tabs=True,
replace_whitespace=True, fix_sentence_endings=False, break_long_words=True,
drop_whitespace=True, break_on_hyphens=True, tabsize=8, *, max_lines=None,
placeholder=' [...]')''')
placeholder=' [...]')
Object for wrapping/filling text. The public interface consists of
the wrap() and fill() methods; the other methods are just there for
subclasses to override in order to tweak the default behaviour.
If you want to completely replace the main wrapping algorithm,
you\'ll probably have to override _wrap_chunks().''')

def test_properly_formated(self):

Expand Down Expand Up @@ -241,7 +246,7 @@ class Type(type): # Type() requires 3 type args, returns class.
__class__ = property({}.__getitem__, {}.__setitem__)
class Object(metaclass=Type):
__slots__ = '__class__'
for meth, mtip in ((Type, default_tip), (Object, default_tip),
for meth, mtip in ((Type, get_spec(type)), (Object, default_tip),
(Object(), '')):
with self.subTest(meth=meth, mtip=mtip):
self.assertEqual(get_spec(meth), mtip)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Get docstrings for IDLE calltips more often by using inspect.getdoc.