Skip to content

Commit ac6d3a4

Browse files
author
dengsheng.chen
committed
Refactor inspect_callable and add a comment
1 parent efa8b04 commit ac6d3a4

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

stackprinter/utils.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,12 @@ def inspect_callable(f):
3232
else:
3333
return None, None, None, None
3434

35-
try:
36-
qname = f.__qualname__
37-
except AttributeError:
38-
qname = None
39-
40-
try:
41-
filepath = code.co_filename
42-
except AttributeError:
43-
filepath = None
44-
45-
try:
46-
ln = code.co_firstlineno
47-
except AttributeError:
48-
ln = None
35+
qname = getattr(f, '__qualname__', None)
36+
37+
# under pypy, builtin code object (like: [].append.__func__.__code__)
38+
# have no co_filename and co_firstlineno
39+
filepath = getattr(code, 'co_filename', None)
40+
ln = getattr(code, 'co_firstlineno', None)
4941

5042
return qname, filepath, owner, ln
5143

0 commit comments

Comments
 (0)