Skip to content

Commit 84d8a81

Browse files
committed
Disambiguate between lambdas and regular functions
1 parent 0bf74b2 commit 84d8a81

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

objgraph.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,8 @@ def _short_repr(obj):
954954
return name + ' (bound)'
955955
else:
956956
return name
957-
if _isinstance(obj, types.LambdaType):
957+
# NB: types.LambdaType is an alias for types.FunctionType!
958+
if _isinstance(obj, types.LambdaType) and obj.__name__ == '<lambda>':
958959
return 'lambda: %s:%s' % (os.path.basename(obj.__code__.co_filename),
959960
obj.__code__.co_firstlineno)
960961
if _isinstance(obj, types.FrameType):

tests.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,14 @@ def test_short_repr_lambda(self):
428428
self.assertEqual('lambda: tests.py:%s' % lambda_lineno,
429429
objgraph._short_repr(f))
430430

431+
def test_short_repr_function(self):
432+
self.assertRegex(objgraph._short_repr(sample_func),
433+
'function sample_func at .*')
434+
435+
436+
def sample_func():
437+
pass
438+
431439

432440
class StubSubprocess(object):
433441

0 commit comments

Comments
 (0)