From 4592aa4247d649e85b01e1acf83ae0089a1ce0cb Mon Sep 17 00:00:00 2001 From: Irit Katriel Date: Fri, 21 Aug 2020 16:38:02 +0100 Subject: [PATCH 1/2] bpo-41609: Fix output of pdb's whatis command for instance methods --- Lib/pdb.py | 12 ++++++------ Lib/test/test_pdb.py | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/Lib/pdb.py b/Lib/pdb.py index 081023526c0ea0..d7d957159458be 100755 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -1312,21 +1312,21 @@ def do_whatis(self, arg): # _getval() already printed the error return code = None - # Is it a function? + # Is it an instance method? try: - code = value.__code__ + code = value.__func__.__code__ except Exception: pass if code: - self.message('Function %s' % code.co_name) + self.message('Method %s' % code.co_name) return - # Is it an instance method? + # Is it a function? try: - code = value.__func__.__code__ + code = value.__code__ except Exception: pass if code: - self.message('Method %s' % code.co_name) + self.message('Function %s' % code.co_name) return # Is it a class? if value.__class__ is type: diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index 1a2bbb382e8642..e56451360d6438 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -425,6 +425,47 @@ def test_list_commands(): (Pdb) continue """ +def test_pdb_whatis_command(): + """Test the whatis command + + >>> myvar = (1,2) + >>> def myfunc(): + ... pass + + >>> class MyClass: + ... def mymethod(self): + ... pass + + >>> def test_function(): + ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() + + >>> with PdbTestInput([ # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE + ... 'whatis myvar', + ... 'whatis myfunc', + ... 'whatis MyClass', + ... 'whatis MyClass()', + ... 'whatis MyClass.mymethod', + ... 'whatis MyClass().mymethod', + ... 'continue', + ... ]): + ... test_function() + --Return-- + > (2)test_function()->None + -> import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() + (Pdb) whatis myvar + + (Pdb) whatis myfunc + Function myfunc + (Pdb) whatis MyClass + Class test.test_pdb.MyClass + (Pdb) whatis MyClass() + + (Pdb) whatis MyClass.mymethod + Function mymethod + (Pdb) whatis MyClass().mymethod + Method mymethod + (Pdb) continue + """ def test_post_mortem(): """Test post mortem traceback debugging. From bb43dcd2163e212cc6c4aa1045bf48a9d6c3eb30 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Fri, 21 Aug 2020 15:51:16 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NEWS.d/next/Library/2020-08-21-15-51-15.bpo-41609.JmiUKG.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2020-08-21-15-51-15.bpo-41609.JmiUKG.rst diff --git a/Misc/NEWS.d/next/Library/2020-08-21-15-51-15.bpo-41609.JmiUKG.rst b/Misc/NEWS.d/next/Library/2020-08-21-15-51-15.bpo-41609.JmiUKG.rst new file mode 100644 index 00000000000000..ecaf40eee7babf --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-08-21-15-51-15.bpo-41609.JmiUKG.rst @@ -0,0 +1 @@ +The pdb whatis command correctly reports instance methods as 'Method' rather than 'Function'. \ No newline at end of file