I have found a bug in inspect.getsource.
I am using Python 2.2.2 on Red-Hat 7.3.
Here is the problem.
--begin bug.py
import inspect
def f(x): return x
print inspect.getsource(f)
--end bug.py
% python bug.py
Traceback (most recent call last):
File "bug.py", line 3, in ?
print inspect.getsource(f)
File "/usr/local/lib/python2.2/inspect.py", line 520,
in getsource
return string.join(lines, '')
File "/usr/local/lib/python2.2/string.py", line 131,
in join
return sep.join(words)
TypeError: sequence expected, NoneType found
Notice that
--begin noproblem.py
import inspect
def f(x):
return x
print inspect.getsource(f)
--end noproblem.py
works:
% python noproblem.py
def f(x):
return x
I discovered this bug in trying to retrieve the source
code for lambda expressions:
--begin lambda.py
import inspect
f=lambda x: x
print inspect.getsource(f)
--begin lambda.py
(same error message).
--
Michele Simionato - Dept. of Physics and Astronomy
210 Allen Hall Pittsburgh PA 15260 U.S.A.
Phone: 001-412-624-9041 Fax: 001-412-624-9163
Home-page: http://www.phyast.pitt.edu/~micheles/
|