[Python-checkins] bpo-42416: Use inspect.getdoc for IDLE calltips (GH-23416)

terryjreedy webhook-mailer at python.org
Fri Nov 20 01:59:19 EST 2020


https://github.com/python/cpython/commit/7ddbaa7a1b3e61847ee99658be6a7268a049e302
commit: 7ddbaa7a1b3e61847ee99658be6a7268a049e302
branch: master
author: Terry Jan Reedy <tjreedy at udel.edu>
committer: terryjreedy <tjreedy at udel.edu>
date: 2020-11-20T01:59:11-05:00
summary:

bpo-42416: Use inspect.getdoc for IDLE calltips (GH-23416)

Inspect.getdoc(ob) sometimes gets docstrings when ob.__doc__ is None.

files:
A Misc/NEWS.d/next/IDLE/2020-11-20-01-30-27.bpo-42415.CyD-va.rst
M Lib/idlelib/NEWS.txt
M Lib/idlelib/calltip.py
M Lib/idlelib/idle_test/test_calltip.py

diff --git a/Lib/idlelib/NEWS.txt b/Lib/idlelib/NEWS.txt
index 3ece623b3aa18..c9f28f62a1a5d 100644
--- a/Lib/idlelib/NEWS.txt
+++ b/Lib/idlelib/NEWS.txt
@@ -3,6 +3,9 @@ Released on 2021-10-04?
 ======================================
 
 
+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.
 
diff --git a/Lib/idlelib/calltip.py b/Lib/idlelib/calltip.py
index 549e224015ccc..40bc5a0ad798f 100644
--- a/Lib/idlelib/calltip.py
+++ b/Lib/idlelib/calltip.py
@@ -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.
@@ -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()
diff --git a/Lib/idlelib/idle_test/test_calltip.py b/Lib/idlelib/idle_test/test_calltip.py
index 489b6899baf42..a76829f3656c8 100644
--- a/Lib/idlelib/idle_test/test_calltip.py
+++ b/Lib/idlelib/idle_test/test_calltip.py
@@ -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):
 
@@ -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)
diff --git a/Misc/NEWS.d/next/IDLE/2020-11-20-01-30-27.bpo-42415.CyD-va.rst b/Misc/NEWS.d/next/IDLE/2020-11-20-01-30-27.bpo-42415.CyD-va.rst
new file mode 100644
index 0000000000000..b61032c1e48e2
--- /dev/null
+++ b/Misc/NEWS.d/next/IDLE/2020-11-20-01-30-27.bpo-42415.CyD-va.rst
@@ -0,0 +1 @@
+Get docstrings for IDLE calltips more often by using inspect.getdoc.



More information about the Python-checkins mailing list