File tree 3 files changed +48
-6
lines changed
3 files changed +48
-6
lines changed Original file line number Diff line number Diff line change @@ -1312,21 +1312,21 @@ def do_whatis(self, arg):
1312
1312
# _getval() already printed the error
1313
1313
return
1314
1314
code = None
1315
- # Is it a function ?
1315
+ # Is it an instance method ?
1316
1316
try :
1317
- code = value .__code__
1317
+ code = value .__func__ . __code__
1318
1318
except Exception :
1319
1319
pass
1320
1320
if code :
1321
- self .message ('Function %s' % code .co_name )
1321
+ self .message ('Method %s' % code .co_name )
1322
1322
return
1323
- # Is it an instance method ?
1323
+ # Is it a function ?
1324
1324
try :
1325
- code = value .__func__ . __code__
1325
+ code = value .__code__
1326
1326
except Exception :
1327
1327
pass
1328
1328
if code :
1329
- self .message ('Method %s' % code .co_name )
1329
+ self .message ('Function %s' % code .co_name )
1330
1330
return
1331
1331
# Is it a class?
1332
1332
if value .__class__ is type :
Original file line number Diff line number Diff line change @@ -425,6 +425,47 @@ def test_list_commands():
425
425
(Pdb) continue
426
426
"""
427
427
428
+ def test_pdb_whatis_command ():
429
+ """Test the whatis command
430
+
431
+ >>> myvar = (1,2)
432
+ >>> def myfunc():
433
+ ... pass
434
+
435
+ >>> class MyClass:
436
+ ... def mymethod(self):
437
+ ... pass
438
+
439
+ >>> def test_function():
440
+ ... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
441
+
442
+ >>> with PdbTestInput([ # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
443
+ ... 'whatis myvar',
444
+ ... 'whatis myfunc',
445
+ ... 'whatis MyClass',
446
+ ... 'whatis MyClass()',
447
+ ... 'whatis MyClass.mymethod',
448
+ ... 'whatis MyClass().mymethod',
449
+ ... 'continue',
450
+ ... ]):
451
+ ... test_function()
452
+ --Return--
453
+ > <doctest test.test_pdb.test_pdb_whatis_command[3]>(2)test_function()->None
454
+ -> import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
455
+ (Pdb) whatis myvar
456
+ <class 'tuple'>
457
+ (Pdb) whatis myfunc
458
+ Function myfunc
459
+ (Pdb) whatis MyClass
460
+ Class test.test_pdb.MyClass
461
+ (Pdb) whatis MyClass()
462
+ <class 'test.test_pdb.MyClass'>
463
+ (Pdb) whatis MyClass.mymethod
464
+ Function mymethod
465
+ (Pdb) whatis MyClass().mymethod
466
+ Method mymethod
467
+ (Pdb) continue
468
+ """
428
469
429
470
def test_post_mortem ():
430
471
"""Test post mortem traceback debugging.
Original file line number Diff line number Diff line change
1
+ The pdb whatis command correctly reports instance methods as 'Method' rather than 'Function'.
You can’t perform that action at this time.
0 commit comments