This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: weird/buggy inspect.getsource behavious
Type: Stage:
Components: Library (Lib) Versions: Python 2.2
process
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: Nosy List: jlgijsbers, sdementen, simon.percivall
Priority: normal Keywords:

Created on 2003-07-11 10:42 by sdementen, last changed 2022-04-10 16:09 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
bug-inspect.py sdementen, 2003-07-11 10:42 code showing bugs in inspect.py
Messages (6)
msg17031 - (view) Author: Sebastien de Menten (sdementen) Date: 2003-07-11 10:42
Using python 2.2.2 on a mandrake 9.1 with the inspect.py of python 
2.2.3 (correction for lambda keyword), I run the following code 
""" 
import inspect 
 
a = [ None, 
      lambda x: x>1 and x<0, 
      None] 
print "Ok",inspect.getsource(a[1]) 
 
if 1: 
    a = [ None, 
          lambda x: x>1 and x<0, 
          None] 
 
    print "Ko",inspect.getsource(a[1]) 
""" 
 
Two weird behaviours occurs 
1. The line "print "Ok",inspect.getsource(a[1])" prints 
Ok       lambda x: x>1 and x<0, 
      None] 
It prints a superfluous line. 
 
2. The line "print "Ko",inspect.getsource(a[1])" raises an exception 
Ko 
Traceback (most recent call last): 
  File "bug-inspect.py", line 13, in ? 
    print "Ko",inspect.getsource(a[1]) 
  File "/usr/lib/python2.2/inspect.py", line 523, in getsource 
    lines, lnum = getsourcelines(object) 
  File "/usr/lib/python2.2/inspect.py", line 515, in getsourcelines 
    else: return getblock(lines[lnum:]), lnum + 1 
  File "/usr/lib/python2.2/inspect.py", line 498, in getblock 
    tokenize.tokenize(ListReader(lines).readline, 
BlockFinder().tokeneater) 
  File "/usr/lib/python2.2/tokenize.py", line 138, in tokenize 
    tokenize_loop(readline, tokeneater) 
  File "/usr/lib/python2.2/tokenize.py", line 144, in tokenize_loop 
    for token_info in generate_tokens(readline): 
  File "/usr/lib/python2.2/tokenize.py", line 218, in generate_tokens 
    raise TokenError, ("EOF in multi-line statement", (lnum, 0)) 
tokenize.TokenError: ('EOF in multi-line statement', (7, 0)) 
 
msg17032 - (view) Author: Johannes Gijsbers (jlgijsbers) * (Python triager) Date: 2004-08-15 12:57
Logged In: YES 
user_id=469548

I can't reproduce problem 2 on today's CVS, but
http://python.org/sf/1006219 fixes problem 1.
msg17033 - (view) Author: Simon Percivall (simon.percivall) Date: 2004-08-19 01:14
Logged In: YES 
user_id=329382

http://www.python.org/sf/1011890 fixes problem 1.
msg17034 - (view) Author: Johannes Gijsbers (jlgijsbers) * (Python triager) Date: 2005-01-09 01:50
Logged In: YES 
user_id=469548

Since patch #1011890 has been checked in, and problem 2 is
unreproducable, I'm closing this.
msg17035 - (view) Author: Simon Percivall (simon.percivall) Date: 2005-01-09 02:17
Logged In: YES 
user_id=329382

Bug 2 is reproducable in Python 2.4, but not in CVS head, which stands to 
reason, since the latest patch to BlockFinder was meant to deal with these 
issues.
msg17036 - (view) Author: Johannes Gijsbers (jlgijsbers) * (Python triager) Date: 2005-01-09 02:23
Logged In: YES 
user_id=469548

Hmm, I couldn't and can't reproduce problem 2 under Python
2.4(.0). But this should be moot, as your BlockFinder patch
will be in 2.4.1.
History
Date User Action Args
2022-04-10 16:09:55adminsetgithub: 38838
2003-07-11 10:42:34sdementencreate