[ python-Bugs-769569 ] weird/buggy inspect.getsource behavious

SourceForge.net noreply at sourceforge.net
Sun Jan 9 03:23:48 CET 2005


Bugs item #769569, was opened at 2003-07-11 12:42
Message generated for change (Comment added) made by jlgijsbers
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=769569&group_id=5470

Category: Python Library
Group: Python 2.2.2
Status: Closed
Resolution: Works For Me
Priority: 5
Submitted By: Sebastien de Menten (sdementen)
Assigned to: Nobody/Anonymous (nobody)
Summary: weird/buggy inspect.getsource behavious

Initial Comment:
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)) 
 

----------------------------------------------------------------------

>Comment By: Johannes Gijsbers (jlgijsbers)
Date: 2005-01-09 03:23

Message:
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.

----------------------------------------------------------------------

Comment By: Simon Percivall (percivall)
Date: 2005-01-09 03:17

Message:
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.

----------------------------------------------------------------------

Comment By: Johannes Gijsbers (jlgijsbers)
Date: 2005-01-09 02:50

Message:
Logged In: YES 
user_id=469548

Since patch #1011890 has been checked in, and problem 2 is
unreproducable, I'm closing this.

----------------------------------------------------------------------

Comment By: Simon Percivall (percivall)
Date: 2004-08-19 03:14

Message:
Logged In: YES 
user_id=329382

http://www.python.org/sf/1011890 fixes problem 1.

----------------------------------------------------------------------

Comment By: Johannes Gijsbers (jlgijsbers)
Date: 2004-08-15 14:57

Message:
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.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=769569&group_id=5470


More information about the Python-bugs-list mailing list