bpo-41609: Fix output of pdb's whatis command for instance methods (GH-21935) (#21977)
(cherry picked from commit 022bc7572f061e1d1132a4db9d085b29707701e7)
Co-authored-by: Irit Katriel <iritkatriel@yahoo.com>
diff --git a/Lib/pdb.py b/Lib/pdb.py
index 0810235..d7d9571 100755
--- a/Lib/pdb.py
+++ b/Lib/pdb.py
@@ -1312,14 +1312,6 @@
# _getval() already printed the error
return
code = None
- # Is it a function?
- try:
- code = value.__code__
- except Exception:
- pass
- if code:
- self.message('Function %s' % code.co_name)
- return
# Is it an instance method?
try:
code = value.__func__.__code__
@@ -1328,6 +1320,14 @@
if code:
self.message('Method %s' % code.co_name)
return
+ # Is it a function?
+ try:
+ code = value.__code__
+ except Exception:
+ pass
+ if code:
+ self.message('Function %s' % code.co_name)
+ return
# Is it a class?
if value.__class__ is type:
self.message('Class %s.%s' % (value.__module__, value.__qualname__))