bug in inspect.getsource

Michele Simionato mis6 at pitt.edu
Thu Dec 26 12:33:44 EST 2002


It seems 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 like f=lambda x: x (same error message).
For lambda expression I don't know a workaround as that in
noproblem.py. Any hint ?


--
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/



More information about the Python-list mailing list