Skip to content
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
12 changes: 6 additions & 6 deletions Lib/pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
41 changes: 41 additions & 0 deletions Lib/test/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The pdb whatis command correctly reports instance methods as 'Method' rather than 'Function'.