[Python-checkins] bpo-41609: Fix output of pdb's whatis command for instance methods (GH-21935) (#21976)
Miss Islington (bot)
webhook-mailer at python.org
Wed Aug 26 21:17:38 EDT 2020
https://github.com/python/cpython/commit/641279e6e51b5d2e10d3fbffe6330e47c94c4bb2
commit: 641279e6e51b5d2e10d3fbffe6330e47c94c4bb2
branch: 3.8
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2020-08-27T03:17:05+02:00
summary:
bpo-41609: Fix output of pdb's whatis command for instance methods (GH-21935) (#21976)
(cherry picked from commit 022bc7572f061e1d1132a4db9d085b29707701e7)
Co-authored-by: Irit Katriel <iritkatriel at yahoo.com>
files:
A Misc/NEWS.d/next/Library/2020-08-21-15-51-15.bpo-41609.JmiUKG.rst
M Lib/pdb.py
M Lib/test/test_pdb.py
diff --git a/Lib/pdb.py b/Lib/pdb.py
index 081023526c0ea..d7d957159458b 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 0e7ae1d86ed80..9c9471a8cc8df 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--
+ > <doctest test.test_pdb.test_pdb_whatis_command[3]>(2)test_function()->None
+ -> import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
+ (Pdb) whatis myvar
+ <class 'tuple'>
+ (Pdb) whatis myfunc
+ Function myfunc
+ (Pdb) whatis MyClass
+ Class test.test_pdb.MyClass
+ (Pdb) whatis MyClass()
+ <class 'test.test_pdb.MyClass'>
+ (Pdb) whatis MyClass.mymethod
+ Function mymethod
+ (Pdb) whatis MyClass().mymethod
+ Method mymethod
+ (Pdb) continue
+ """
def test_post_mortem():
"""Test post mortem traceback debugging.
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 0000000000000..ecaf40eee7bab
--- /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
More information about the Python-checkins
mailing list